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 <[email protected]>
Signed-off-by: ISHIDA Wataru <[email protected]>
---
 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 3546c92..7eb9c48 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 f08ac1e..67ba85c 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
-- 
1.9.1


------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to