hold a raw update_msg in ReceivedRoute to deliver unmodified update msg
to bmp server.

this patch also removes some redunduncy in peer.py

Signed-off-by: ISHIDA Wataru <ishida.wat...@lab.ntt.co.jp>
---
 ryu/services/protocols/bgp/bmp.py  |   5 +-
 ryu/services/protocols/bgp/peer.py | 122 ++++++++++++-------------------------
 2 files changed, 41 insertions(+), 86 deletions(-)

diff --git a/ryu/services/protocols/bgp/bmp.py 
b/ryu/services/protocols/bgp/bmp.py
index 4fbbecb..4465bef 100644
--- a/ryu/services/protocols/bgp/bmp.py
+++ b/ryu/services/protocols/bgp/bmp.py
@@ -84,7 +84,6 @@ class BMPClient(Activity):
     def on_adj_rib_in_changed(self, data):
         peer = data['peer']
         path = data['received_route']
-        update_msg = peer._construct_update(path)
         msg = self._construct_route_monitoring(peer, path)
         self._send(msg)
 
@@ -94,7 +93,6 @@ class BMPClient(Activity):
         self._send(msg)
 
         for path in peer._adj_rib_in.itervalues():
-            update_msg = peer._construct_update(path)
             msg = self._construct_route_monitoring(peer, path)
             self._send(msg)
 
@@ -171,11 +169,10 @@ 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)
 
-        msg = bmp.BMPRouteMonitoring(bgp_update=bgp_update,
+        msg = bmp.BMPRouteMonitoring(bgp_update=path.path,
                                      peer_type=peer_type,
                                      is_post_policy=is_post_policy,
                                      peer_distinguisher=peer_distinguisher,
diff --git a/ryu/services/protocols/bgp/peer.py 
b/ryu/services/protocols/bgp/peer.py
index 4dafb10..ccf4635 100644
--- a/ryu/services/protocols/bgp/peer.py
+++ b/ryu/services/protocols/bgp/peer.py
@@ -1338,20 +1338,44 @@ class Peer(Source, Sink, NeighborConfListener, 
Activity):
 
         nlri_list = update_msg.nlri
         withdraw_list = update_msg.withdrawn_routes
+        msg_rf = None
+        paths = None
 
         if mp_reach_attr:
             # Extract advertised paths from given message.
-            self._extract_and_handle_mpbgp_new_paths(update_msg)
+            paths = self._extract_and_handle_mpbgp_new_paths(update_msg)
+            msg_rf = mp_reach_attr.route_family
 
         if mp_unreach_attr:
             # Extract withdraws from given message.
-            self._extract_and_handle_mpbgp_withdraws(mp_unreach_attr)
+            paths = self._extract_and_handle_mpbgp_withdraws(mp_unreach_attr)
 
         if nlri_list:
-            self._extract_and_handle_bgp4_new_paths(update_msg)
+            paths = self._extract_and_handle_bgp4_new_paths(update_msg)
 
         if withdraw_list:
-            self._extract_and_handle_bgp4_withdraws(withdraw_list)
+            paths = self._extract_and_handle_bgp4_withdraws(withdraw_list)
+
+        paths = paths if paths else []
+        for path in paths:
+            block, blocked_cause = self._apply_in_filter(path)
+            received_route = ReceivedRoute(update_msg, self, block)
+            nlri_str = path.nlri.formatted_nlri_str
+            self._adj_rib_in[nlri_str] = received_route
+            self._signal_bus.adj_rib_in_changed(self, received_route)
+
+            if not block:
+                if msg_rf and msg_rf == RF_RTC_UC \
+                        and self._init_rtc_nlri_path is not None:
+                    self._init_rtc_nlri_path.append(path)
+                else:
+                    # Update appropriate table with new paths.
+                    tm = self._core_service.table_manager
+                    tm.learn_path(path)
+            else:
+                LOG.debug('prefix : %s is blocked by in-bound filter : %s'
+                          % (nlri_str, blocked_cause))
+
 
     def _extract_and_handle_bgp4_new_paths(self, update_msg):
         """Extracts new paths advertised in the given update message's
@@ -1391,8 +1415,8 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
             return
 
         # Create path instances for each NLRI from the update message.
+        paths = []
         for msg_nlri in msg_nlri_list:
-            LOG.debug('NLRI: %s' % msg_nlri)
             new_path = bgp_utils.create_path(
                 self,
                 msg_nlri,
@@ -1400,21 +1424,7 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
                 nexthop=next_hop
             )
             LOG.debug('Extracted paths from Update msg.: %s' % new_path)
-
-            block, blocked_cause = self._apply_in_filter(new_path)
-
-            nlri_str = new_path.nlri.formatted_nlri_str
-            received_route = ReceivedRoute(new_path, self, block)
-            self._adj_rib_in[nlri_str] = received_route
-            self._signal_bus.adj_rib_in_changed(self, received_route)
-
-            if not block:
-                # Update appropriate table with new paths.
-                tm = self._core_service.table_manager
-                tm.learn_path(new_path)
-            else:
-                LOG.debug('prefix : %s is blocked by in-bound filter : %s'
-                          % (msg_nlri, blocked_cause))
+            paths.append(new_path)
 
         # If update message had any qualifying new paths, do some book-keeping.
         if msg_nlri_list:
@@ -1427,6 +1437,8 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
                 LOG.error('Max. prefix allowed for this neighbor '
                           'exceeded.')
 
+        return paths
+
     def _extract_and_handle_bgp4_withdraws(self, withdraw_list):
         """Extracts withdraws advertised in the given update message's
          *MpUnReachNlri* attribute.
@@ -1450,32 +1462,12 @@ class Peer(Source, Sink, NeighborConfListener, 
Activity):
             )
             return
 
-        w_nlris = withdraw_list
-        if not w_nlris:
+        if not withdraw_list:
             # If this is EOR of some kind, handle it
             self._handle_eor(msg_rf)
 
-        for w_nlri in w_nlris:
-            w_path = bgp_utils.create_path(
-                self,
-                w_nlri,
-                is_withdraw=True
-            )
-
-            block, blocked_cause = self._apply_in_filter(w_path)
-
-            received_route = ReceivedRoute(w_path, self, block)
-            nlri_str = w_nlri.formatted_nlri_str
-            self._adj_rib_in[nlri_str] = received_route
-            self._signal_bus.adj_rib_in_changed(self, received_route)
-
-            if not block:
-                # Update appropriate table with withdraws.
-                tm = self._core_service.table_manager
-                tm.learn_path(w_path)
-            else:
-                LOG.debug('prefix : %s is blocked by in-bound filter : %s'
-                          % (nlri_str, blocked_cause))
+        f = lambda nlri : bgp_utils.create_path(self, nlri, is_withdraw=True)
+        return [f(nlri) for nlri in withdraw_list]
 
     def _extract_and_handle_mpbgp_new_paths(self, update_msg):
         """Extracts new paths advertised in the given update message's
@@ -1545,6 +1537,7 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
             return
 
         # Create path instances for each NLRI from the update message.
+        paths = []
         for msg_nlri in msg_nlri_list:
             new_path = bgp_utils.create_path(
                 self,
@@ -1553,25 +1546,7 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
                 nexthop=next_hop
             )
             LOG.debug('Extracted paths from Update msg.: %s' % new_path)
-
-            block, blocked_cause = self._apply_in_filter(new_path)
-
-            received_route = ReceivedRoute(new_path, self, block)
-            nlri_str = msg_nlri.formatted_nlri_str
-            self._adj_rib_in[nlri_str] = received_route
-            self._signal_bus.adj_rib_in_changed(self, received_route)
-
-            if not block:
-                if msg_rf == RF_RTC_UC \
-                        and self._init_rtc_nlri_path is not None:
-                    self._init_rtc_nlri_path.append(new_path)
-                else:
-                    # Update appropriate table with new paths.
-                    tm = self._core_service.table_manager
-                    tm.learn_path(new_path)
-            else:
-                LOG.debug('prefix : %s is blocked by in-bound filter : %s'
-                          % (msg_nlri, blocked_cause))
+            paths.append(new_path)
 
         # If update message had any qualifying new paths, do some book-keeping.
         if msg_nlri_list:
@@ -1583,6 +1558,7 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
                     self.state.get_count(PeerCounterNames.RECV_PREFIXES)):
                 LOG.error('Max. prefix allowed for this neighbor '
                           'exceeded.')
+        return paths
 
     def _extract_and_handle_mpbgp_withdraws(self, mp_unreach_attr):
         """Extracts withdraws advertised in the given update message's
@@ -1612,26 +1588,8 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
             # If this is EOR of some kind, handle it
             self._handle_eor(msg_rf)
 
-        for w_nlri in w_nlris:
-            w_path = bgp_utils.create_path(
-                self,
-                w_nlri,
-                is_withdraw=True
-            )
-            block, blocked_cause = self._apply_in_filter(w_path)
-
-            received_route = ReceivedRoute(w_path, self, block)
-            nlri_str = w_nlri.formatted_nlri_str
-            self._adj_rib_in[nlri_str] = received_route
-            self._signal_bus.adj_rib_in_changed(self, received_route)
-
-            if not block:
-                # Update appropriate table with withdraws.
-                tm = self._core_service.table_manager
-                tm.learn_path(w_path)
-            else:
-                LOG.debug('prefix : %s is blocked by in-bound filter : %s'
-                          % (w_nlri, blocked_cause))
+        f = lambda nlri : bgp_utils.create_path(self, nlri, is_withdraw=True)
+        return [f(nlri) for nlri in w_nlris]
 
     def _handle_eor(self, route_family):
         """Currently we only handle EOR for RTC address-family.
-- 
1.9.1


------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to