On Thu, 03 Jul 2014 10:42:39 +0900 (JST)
FUJITA Tomonori <[email protected]> wrote:

> 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.

Oops, found a bug. here's a new one.


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..dcf9567 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, nexthop=None,
+                            is_withdraw=False):
         src_ver_num = 1
         peer = None
         # set mandatory path attributes
@@ -511,11 +512,13 @@ class TableCoreManager(object):
         masklen = net.prefixlen
         if netaddr.valid_ipv4(ip):
             _nlri = IPAddrPrefix(masklen, ip)
-            nexthop = '0.0.0.0'
+            if nexthop is None:
+                nexthop = '0.0.0.0'
             p = Ipv4Path
         else:
             _nlri = IP6AddrPrefix(masklen, ip)
-            nexthop = '::'
+            if nexthop is None:
+                nexthop = '::'
             p = Ipv6Path
 
         new_path = p(peer, _nlri, src_ver_num,
diff --git a/ryu/services/protocols/bgp/peer.py 
b/ryu/services/protocols/bgp/peer.py
index 47f3c17..47b562d 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.nexthop != '0.0.0.0':
+            return path.nexthop
+        if route_family == RF_IPv6_UC and path.nexthop != '::':
+            return path.nexthop
+
         # 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