Skip to content

Commit

Permalink
bgp: supporting best_path_change_handler for Vpnv4/6 prefix in BGPSpe…
Browse files Browse the repository at this point in the history
…aker

BGPSpeaker is aware of "best_path_change_handler" in MPLS-VPN topology.
This feature is available in calculating Best Path Selection of VPNv4/6 prefixes.

Signed-off-by: Toshiki Tsuboi <[email protected]>
Signed-off-by: FUJITA Tomonori <[email protected]>
  • Loading branch information
ttsubo authored and fujita committed Oct 28, 2014
1 parent 16ea9e4 commit b6093c3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
35 changes: 28 additions & 7 deletions ryu/services/protocols/bgp/bgpspeaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
from ryu.services.protocols.bgp.rtconf.neighbors import LOCAL_ADDRESS
from ryu.services.protocols.bgp.rtconf.neighbors import LOCAL_PORT
from ryu.services.protocols.bgp.info_base.base import Filter
from ryu.services.protocols.bgp.info_base.ipv4 import Ipv4Path
from ryu.services.protocols.bgp.info_base.ipv6 import Ipv6Path
from ryu.services.protocols.bgp.info_base.vpnv4 import Vpnv4Path
from ryu.services.protocols.bgp.info_base.vpnv6 import Vpnv6Path


NEIGHBOR_CONF_MED = 'multi_exit_disc'
Expand All @@ -80,16 +84,19 @@ class EventPrefix(object):
route_dist None in the case of ipv4 or ipv6 family
prefix A prefix was changed
nexthop The nexthop of the changed prefix
label mpls label for vpnv4 prefix
is_withdraw True if this prefix has gone otherwise False
================ ======================================================
"""

def __init__(self, remote_as, route_dist, prefix, nexthop, is_withdraw):
def __init__(self, remote_as, route_dist, prefix, nexthop, label,
is_withdraw):
self.remote_as = remote_as
self.route_dist = route_dist
self.prefix = prefix
self.nexthop = nexthop
self.label = label
self.is_withdraw = is_withdraw


Expand Down Expand Up @@ -145,13 +152,27 @@ def __init__(self, as_number, router_id,
hub.spawn(ssh.SSH_CLI_CONTROLLER.start)

def _notify_best_path_changed(self, path, is_withdraw):
if not path.source:
# ours
if path.source:
nexthop = path.nexthop
is_withdraw = is_withdraw
remote_as = path.source.remote_as
else:
return

if isinstance(path, Ipv4Path) or isinstance(path, Ipv6Path):
prefix = path.nlri.addr + '/' + str(path.nlri.length)
route_dist = None
label = None
elif isinstance(path, Vpnv4Path) or isinstance(path, Vpnv6Path):
prefix = path.nlri.prefix
route_dist = path.nlri.route_dist
label = path.nlri.label_list
else:
return
ev = EventPrefix(remote_as=path.source.remote_as,
route_dist=None,
prefix=path.nlri.addr + '/' + str(path.nlri.length),
nexthop=path.nexthop, is_withdraw=is_withdraw)

ev = EventPrefix(remote_as, route_dist, prefix, nexthop, label,
is_withdraw)

if self._best_path_change_handler:
self._best_path_change_handler(ev)

Expand Down
2 changes: 2 additions & 0 deletions ryu/services/protocols/bgp/info_base/vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class VpnDest(Destination, NonVrfPathProcessingMixin):
def _best_path_lost(self):
old_best_path = self._best_path
NonVrfPathProcessingMixin._best_path_lost(self)
self._core_service._signal_bus.best_path_changed(old_best_path, True)

# Best-path might have been imported into VRF tables, we have to
# withdraw from them, if the source is a peer.
Expand All @@ -102,6 +103,7 @@ def _best_path_lost(self):

def _new_best_path(self, best_path):
NonVrfPathProcessingMixin._new_best_path(self, best_path)
self._core_service._signal_bus.best_path_changed(best_path, False)

# Extranet feature requires that we import new best path into VRFs.
tm = self._core_service.table_manager
Expand Down

0 comments on commit b6093c3

Please sign in to comment.