On Wed,  2 Jul 2014 16:07:01 +0900 (JST)
[email protected] (YAMAMOTO Takashi) wrote:

>> 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.
> 
> is it difficult to support prefix_add next_hop argument for non-VPN cases?

Not at all. Here's a patch.

> i've heard there are use cases where it's necessary to specify
> next_hop in a per-prefix basis.

Do you have the details? If there are such use cases, surely we can
support them.

diff --git a/ryu/services/protocols/bgp/api/rtconf.py 
b/ryu/services/protocols/bgp/api/rtconf.py
index 93eeb18..f5bbc44 100644
--- a/ryu/services/protocols/bgp/api/rtconf.py
+++ b/ryu/services/protocols/bgp/api/rtconf.py
@@ -174,9 +174,9 @@ def get_vrfs_conf():
 
 
 @register(name='network.add')
-def add_network(prefix):
+def add_network(prefix, next_hop=None):
     tm = CORE_MANAGER.get_core_service().table_manager
-    tm.add_to_global_table(prefix)
+    tm.add_to_global_table(prefix, next_hop)
     return True
 
 
diff --git a/ryu/services/protocols/bgp/core_managers/table_manager.py 
b/ryu/services/protocols/bgp/core_managers/table_manager.py
index a4aad99..4dac1d5 100644
--- a/ryu/services/protocols/bgp/core_managers/table_manager.py
+++ b/ryu/services/protocols/bgp/core_managers/table_manager.py
@@ -495,7 +495,8 @@ class TableCoreManager(object):
             gen_lbl=True
         )
 
-    def add_to_global_table(self, prefix, is_withdraw=False):
+    def add_to_global_table(self, prefix, next_hop=None,
+                            is_withdraw=False):
         src_ver_num = 1
         peer = None
         # set mandatory path attributes
@@ -521,6 +522,8 @@ class TableCoreManager(object):
         new_path = p(peer, _nlri, src_ver_num,
                      pattrs=pathattrs, nexthop=nexthop,
                      is_withdraw=is_withdraw)
+        if next_hop:
+            new_path.next_hop = next_hop
 
         # add to global ipv4 table and propagates to neighbors
         self.learn_path(new_path)
diff --git a/ryu/services/protocols/bgp/peer.py 
b/ryu/services/protocols/bgp/peer.py
index 47f3c17..c42cb60 100644
--- a/ryu/services/protocols/bgp/peer.py
+++ b/ryu/services/protocols/bgp/peer.py
@@ -581,7 +581,7 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
         update = BGPUpdate(path_attributes=[mpunreach_attr])
         self.enque_outgoing_msg(update)
 
-    def _session_next_hop(self, route_family):
+    def _session_next_hop(self, path):
         """Returns nexthop address relevant to current session
 
         Nexthop used can depend on capabilities of the session. If VPNv6
@@ -589,6 +589,13 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
         IPv4 mapped IPv6 address. In other cases we can use connection end
         point/local ip address.
         """
+        route_family = path.route_family
+
+        if route_family == RF_IPv4_UC and path.next_hop != '0.0.0.0':
+            return path.next_hop
+        if route_family == RF_IPv6_UC and path.next_hop != '::':
+            return path.next_hop
+
         # By default we use BGPS's interface IP with this peer as next_hop.
         if self._neigh_conf.next_hop:
             next_hop = self._neigh_conf.next_hop
@@ -638,7 +645,7 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
             # 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.route_family)
+            next_hop = self._session_next_hop(path)
             # If this is a iBGP peer.
             if not self.is_ebgp_peer() and path.source is not None:
                 # If the path came from a bgp peer and not from NC, according

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to