From 2a4423fda3efb78368a9c8fdd5d8a48caf359c96 Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Fri, 21 Aug 2015 12:25:59 +0900 Subject: [PATCH] bgp: Added support to indicate the next hop IP address for the BGP module If the path has a next hop value set, it should be used in the BGP Update message first. This changes to logic to use the check for the next hop in the order prefix/path->peer config->speaker config. This will allow for sending the nexthop as part of the add_prefix message and allow for overiding the nexthop of the peer if one is set. Based-on: Alan Quillin Signed-off-by: ISHIDA Wataru Signed-off-by: FUJITA Tomonori --- ryu/services/protocols/bgp/info_base/base.py | 7 +++++++ ryu/services/protocols/bgp/peer.py | 7 ++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ryu/services/protocols/bgp/info_base/base.py b/ryu/services/protocols/bgp/info_base/base.py index 3546c92b..7eb9c48d 100644 --- a/ryu/services/protocols/bgp/info_base/base.py +++ b/ryu/services/protocols/bgp/info_base/base.py @@ -809,6 +809,13 @@ class Path(object): return not interested_rts.isdisjoint(curr_rts) + def is_local(self): + return self._source == None + + def has_nexthop(self): + return not (not self._nexthop or self._nexthop == '0.0.0.0' or + self._nexthop == '::') + def __str__(self): return ( 'Path(source: %s, nlri: %s, source ver#: %s, ' diff --git a/ryu/services/protocols/bgp/peer.py b/ryu/services/protocols/bgp/peer.py index f08ac1e8..67ba85c0 100644 --- a/ryu/services/protocols/bgp/peer.py +++ b/ryu/services/protocols/bgp/peer.py @@ -851,11 +851,12 @@ class Peer(Source, Sink, NeighborConfListener, Activity): nlri_list = [path.nlri] # By default we use BGPS's interface IP with this peer as next_hop. - # TODO(PH): change to use protocol's local address. - # next_hop = self.host_bind_ip next_hop = self._session_next_hop(path) + if path.is_local() and path.has_nexthop(): + next_hop = path.nexthop + # If this is a iBGP peer. - if not self.is_ebgp_peer() and path.source is not None: + if not self.is_ebgp_peer() and not path.is_local(): # If the path came from a bgp peer and not from NC, according # to RFC 4271 we should not modify next_hop. # However RFC 4271 allows us to change next_hop