diff options
-rw-r--r-- | ryu/services/protocols/bgp/api/rtconf.py | 4 | ||||
-rw-r--r-- | ryu/services/protocols/bgp/core_managers/table_manager.py | 9 | ||||
-rw-r--r-- | ryu/services/protocols/bgp/peer.py | 11 |
3 files changed, 17 insertions, 7 deletions
diff --git a/ryu/services/protocols/bgp/api/rtconf.py b/ryu/services/protocols/bgp/api/rtconf.py index 93eeb18e..f5bbc446 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 a4aad997..dcf95670 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 47f3c17b..47b562d0 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 |