Current implementation of bmp client uses Peer._construct_update()
which modifies original BGPUpdate message for sending to peers.
This function is not appropriate to use for bmp client, because
bmp client must send a BGPUpdate message which contains unmodified path
attributes. Fix this by introducing BMPClient._construct_update().

Signed-off-by: ISHIDA Wataru <[email protected]>
---
 ryu/services/protocols/bgp/bmp.py | 43 +++++++++++++++++++++++++++++++++++----
 1 file changed, 39 insertions(+), 4 deletions(-)

diff --git a/ryu/services/protocols/bgp/bmp.py 
b/ryu/services/protocols/bgp/bmp.py
index 4fbbecb..78175ee 100644
--- a/ryu/services/protocols/bgp/bmp.py
+++ b/ryu/services/protocols/bgp/bmp.py
@@ -22,6 +22,11 @@ import socket
 import logging
 from calendar import timegm
 from ryu.services.protocols.bgp.signals.emit import BgpSignalBus
+from ryu.services.protocols.bgp.info_base.ipv4 import Ipv4Path
+from ryu.lib.packet.bgp import BGPUpdate
+from ryu.lib.packet.bgp import BGPPathAttributeNextHop
+from ryu.lib.packet.bgp import BGPPathAttributeMpReachNLRI
+from ryu.lib.packet.bgp import BGPPathAttributeMpUnreachNLRI
 
 LOG = logging.getLogger('bgpspeaker.bmp')
 
@@ -159,7 +164,37 @@ class BMPClient(Activity):
                                            peer_bgp_id=peer_bgp_id,
                                            timestamp=0)
 
-    def _construct_route_monitoring(self, peer, path):
+    def _construct_update(self, path):
+        # Get copy of path's path attributes.
+        new_pathattr = [attr for attr in path.pathattr_map.itervalues()]
+
+        if path.is_withdraw:
+            if isinstance(path, Ipv4Path):
+                return BGPUpdate(withdrawn_routes=[path.nlri],
+                                 path_attributes=new_pathattr)
+            else:
+                mpunreach_attr = BGPPathAttributeMpUnreachNLRI(
+                    path.route_family.afi, path.route_family.safi, [path.nlri]
+                )
+                new_pathattr.append(mpunreach_attr)
+        else:
+            if isinstance(path, Ipv4Path):
+                nexthop_attr = BGPPathAttributeNextHop(path.nexthop)
+                new_pathattr.append(nexthop_attr)
+                return BGPUpdate(nlri=[path.nlri],
+                                 path_attributes=new_pathattr)
+            else:
+                mpnlri_attr = BGPPathAttributeMpReachNLRI(
+                    path.route_family.afi,
+                    path.route_family.safi,
+                    path.nexthop,
+                    [path.nlri]
+                )
+                new_pathattr.append(mpnlri_attr)
+
+        return BGPUpdate(path_attributes=new_pathattr)
+
+    def _construct_route_monitoring(self, peer, route):
         if peer.is_mpbgp_cap_valid(bgp.RF_IPv4_VPN) or \
                 peer.is_mpbgp_cap_valid(bgp.RF_IPv6_VPN):
             peer_type = bmp.BMP_PEER_TYPE_L3VPN
@@ -171,9 +206,9 @@ class BMPClient(Activity):
         peer_bgp_id = peer.protocol.recv_open_msg.bgp_identifier
         peer_address, _ = peer.protocol._remotename
 
-        bgp_update = peer._construct_update(path)
-        is_post_policy = not path.filtered
-        timestamp = timegm(path.timestamp)
+        bgp_update = self._construct_update(route.path)
+        is_post_policy = not route.filtered
+        timestamp = timegm(route.timestamp)
 
         msg = bmp.BMPRouteMonitoring(bgp_update=bgp_update,
                                      peer_type=peer_type,
-- 
1.9.1


------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to