bgp: support specifying nexthop per prefix

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Reviewed-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
This commit is contained in:
FUJITA Tomonori 2014-07-07 22:17:29 +09:00
parent 8051160db1
commit a3f24e8cca
3 changed files with 17 additions and 7 deletions

View File

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

View File

@ -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,

View File

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