Skip to content

Commit

Permalink
bgp: support specifying next hop for neighbor
Browse files Browse the repository at this point in the history
neighbor_add method takes 'next_hop' parameter. If not specified, like
before, host's ip connected to the neighbor is used as a next hop.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
  • Loading branch information
fujita committed Jun 30, 2014
1 parent f2e62c2 commit bf58248
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
7 changes: 6 additions & 1 deletion ryu/services/protocols/bgp/bgpspeaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from ryu.services.protocols.bgp.rtconf.neighbors import DEFAULT_CAP_MBGP_IPV4
from ryu.services.protocols.bgp.rtconf.neighbors import DEFAULT_CAP_MBGP_VPNV4
from ryu.services.protocols.bgp.rtconf.neighbors import DEFAULT_CAP_MBGP_VPNV6
from ryu.services.protocols.bgp.rtconf.neighbors import PEER_NEXT_HOP
from ryu.services.protocols.bgp.application import RyuBGPSpeaker


Expand Down Expand Up @@ -165,7 +166,8 @@ def shutdown(self):
def neighbor_add(self, address, remote_as,
enable_ipv4=DEFAULT_CAP_MBGP_IPV4,
enable_vpnv4=DEFAULT_CAP_MBGP_VPNV4,
enable_vpnv6=DEFAULT_CAP_MBGP_VPNV6):
enable_vpnv6=DEFAULT_CAP_MBGP_VPNV6,
next_hop=None):
""" This method registers a new neighbor. The BGP speaker tries to
establish a bgp session with the peer (accepts a connection
from the peer and also tries to connect to it).
Expand All @@ -186,10 +188,13 @@ def neighbor_add(self, address, remote_as,
``enable_vpnv6`` enables VPNv6 address family for this
neighbor. The default is False.
``next_hop`` specifies the next hop IP address. If not
specified, host's ip address to access to a peer is used.
"""
bgp_neighbor = {}
bgp_neighbor[neighbors.IP_ADDRESS] = address
bgp_neighbor[neighbors.REMOTE_AS] = remote_as
bgp_neighbor[PEER_NEXT_HOP] = next_hop
# v6 advertizement is available with only v6 peering
if netaddr.valid_ipv4(address):
bgp_neighbor[CAP_MBGP_IPV4] = enable_ipv4
Expand Down
5 changes: 4 additions & 1 deletion ryu/services/protocols/bgp/peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,10 @@ def _session_next_hop(self, route_family):
point/local ip address.
"""
# By default we use BGPS's interface IP with this peer as next_hop.
next_hop = self.host_bind_ip
if self._neigh_conf.next_hop:
next_hop = self._neigh_conf.next_hop
else:
next_hop = self.host_bind_ip
if route_family == RF_IPv6_VPN:
# Next hop ipv4_mapped ipv6
def _ipv4_mapped_ipv6(ipv4):
Expand Down
19 changes: 18 additions & 1 deletion ryu/services/protocols/bgp/rtconf/neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
CHANGES = 'changes'
LOCAL_ADDRESS = 'local_address'
LOCAL_PORT = 'local_port'
PEER_NEXT_HOP = 'next_hop'

# Default value constants.
DEFAULT_CAP_GR_NULL = True
Expand Down Expand Up @@ -132,6 +133,14 @@ def validate_local_address(ip_address):
return str(netaddr.IPAddress(ip_address))


@validate(name=PEER_NEXT_HOP)
def validate_next_hop(ip_address):
if not valid_ip_address(ip_address):
raise ConfigValueError(desc='Invalid next_hop ip_address: %s' %
ip_address)
return str(netaddr.IPAddress(ip_address))


@validate(name=LOCAL_PORT)
def validate_local_port(port):
if not isinstance(port, (int, long)):
Expand Down Expand Up @@ -164,7 +173,8 @@ class NeighborConf(ConfWithId, ConfWithStats):
CAP_RTC, RTC_AS, HOLD_TIME,
ENABLED, MULTI_EXIT_DISC, MAX_PREFIXES,
ADVERTISE_PEER_AS, SITE_OF_ORIGINS,
LOCAL_ADDRESS, LOCAL_PORT])
LOCAL_ADDRESS, LOCAL_PORT,
PEER_NEXT_HOP])

def __init__(self, **kwargs):
super(NeighborConf, self).__init__(**kwargs)
Expand Down Expand Up @@ -213,6 +223,9 @@ def _init_opt_settings(self, **kwargs):
self._settings[LOCAL_PORT] = compute_optional_conf(
LOCAL_PORT, None, **kwargs)

self._settings[PEER_NEXT_HOP] = compute_optional_conf(
PEER_NEXT_HOP, None, **kwargs)

# RTC configurations.
self._settings[CAP_RTC] = \
compute_optional_conf(CAP_RTC, DEFAULT_CAP_RTC, **kwargs)
Expand Down Expand Up @@ -265,6 +278,10 @@ def host_bind_ip(self):
def host_bind_port(self):
return self._settings[LOCAL_PORT]

@property
def next_hop(self):
return self._settings[PEER_NEXT_HOP]

# =========================================================================
# Optional attributes with valid defaults.
# =========================================================================
Expand Down

0 comments on commit bf58248

Please sign in to comment.