summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2016-09-05 09:41:41 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-09-07 10:02:15 +0900
commit5d1d8648ab0830206523fb944f19a4805bba1d3d (patch)
tree7e4fc7256655f95754f58d9d8da3dcef1e90ac18
parent57aa646d61932829062646a095a15ebdbe17f7b1 (diff)
BGPSpeaker: Enable to get path from EventPrefix
To get more detail information about BGP route by using best_path_change_handler, this patch adds path member into EventPrefix and implements property to get existing attributes. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/services/protocols/bgp/bgpspeaker.py74
1 files changed, 47 insertions, 27 deletions
diff --git a/ryu/services/protocols/bgp/bgpspeaker.py b/ryu/services/protocols/bgp/bgpspeaker.py
index 62ba1462..3fd4bfff 100644
--- a/ryu/services/protocols/bgp/bgpspeaker.py
+++ b/ryu/services/protocols/bgp/bgpspeaker.py
@@ -78,6 +78,7 @@ 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
+from ryu.services.protocols.bgp.info_base.evpn import EvpnPath
NEIGHBOR_CONF_MED = MULTI_EXIT_DISC # for backward compatibility
@@ -95,23 +96,56 @@ class EventPrefix(object):
Attribute Description
================ ======================================================
remote_as The AS number of a peer that caused this change
- route_dist None in the case of ipv4 or ipv6 family
+ 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
+ label MPLS label for VPNv4, VPNv6 or EVPN prefix
+ path An instance of ``info_base.base.Path`` subclass
is_withdraw True if this prefix has gone otherwise False
================ ======================================================
"""
- 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
+ def __init__(self, path, is_withdraw):
+ self.path = path
self.is_withdraw = is_withdraw
+ @property
+ def remote_as(self):
+ return self.path.source.remote_as
+
+ @property
+ def route_dist(self):
+ if (isinstance(self.path, Vpnv4Path)
+ or isinstance(self.path, Vpnv6Path)
+ or isinstance(self.path, EvpnPath)):
+ return self.path.nlri.route_dist
+ else:
+ return None
+
+ @property
+ def prefix(self):
+ if isinstance(self.path, Ipv4Path) or isinstance(self.path, Ipv6Path):
+ return self.path.nlri.addr + '/' + str(self.path.nlri.length)
+ elif (isinstance(self.path, Vpnv4Path)
+ or isinstance(self.path, Vpnv6Path)
+ or isinstance(self.path, EvpnPath)):
+ return self.path.nlri.prefix
+ else:
+ return None
+
+ @property
+ def nexthop(self):
+ return self.path.nexthop
+
+ @property
+ def label(self):
+ if (isinstance(self.path, Vpnv4Path)
+ or isinstance(self.path, Vpnv6Path)
+ or isinstance(self.path, EvpnPath)):
+ return getattr(self.path.nlri, 'label_list', None)
+ else:
+ return None
+
class BGPSpeaker(object):
def __init__(self, as_number, router_id,
@@ -189,26 +223,12 @@ class BGPSpeaker(object):
self._peer_up_handler(remote_ip, remote_as)
def _notify_best_path_changed(self, path, is_withdraw):
- 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:
+ if (not path.source
+ or not isinstance(path, (Ipv4Path, Ipv6Path,
+ Vpnv4Path, Vpnv6Path, EvpnPath))):
return
- ev = EventPrefix(remote_as, route_dist, prefix, nexthop, label,
- is_withdraw)
+ ev = EventPrefix(path, is_withdraw)
if self._best_path_change_handler:
self._best_path_change_handler(ev)