Hi Hadem,

In stead of monitoring the UPDATE message arrivals, how about monitoring
adj-RIB-in like the attached patch?

With this patch, I could get new (or deleted) paths as "event" like the
following.

====
# my_bgp_app.py

from ryu.base import app_manager
from ryu.controller.handler import set_ev_cls
from ryu.services.protocols.bgp import application as bgp_application


class MyBGPApp(app_manager.RyuApp):
    _CONTEXTS = {
        'ryubgpspeaker': bgp_application.RyuBGPSpeaker,
    }

    def __init__(self, *args, **kwargs):
        super(MyBGPApp, self).__init__(*args, **kwargs)

        # Stores "ryu.services.protocols.bgp.application.RyuBGPSpeaker"
        # instance in order to call the APIs of
        # "ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker" via
        # "self.app.speaker".
        # Please note at this time, "BGPSpeaker" is NOT instantiated yet.
        self.app = kwargs['ryubgpspeaker']

    @set_ev_cls(bgp_application.EventAdjRibInChanged)
    def _best_patch_changed_handler(self, ev):
        self.logger.info(
            'adj-RIB-in path changed: is_withdraw=%s, path=%s, '
            'peer_ip=%s, peer_as=%d',
            ev.is_withdraw, ev.path, ev.peer_ip, ev.peer_as)
====

e.g.)
$ ryu-manager my_bgp_app.py \
    --bgp-app-config-file ryu/services/protocols/bgp/bgp_sample_conf.py
...(snip)...
adj-RIB-in path changed: is_withdraw=False, path=Path(source: Peer(ip: 10.0.0.2, asn: 65002), nlri: BGPNLRI(addr='10.2.1.0',length=24), source ver#: 1, path attrs.: {1: BGPPathAttributeOrigin(flags=64,length=1,type=1,value=2), 2: BGPPathAttributeAsPath(flags=64,length=6,type=2,value=[[65002]]), 3: BGPPathAttributeNextHop(flags=64,length=4,type=3,value='10.0.0.2')}, nexthop: 10.0.0.2, is_withdraw: False), peer_ip=10.0.0.2, peer_as=65002
...(snip)...


Thanks,
Iwase


On 2018年01月19日 17:56, Pynbiang Hadem wrote:
Hi Iwase,

Calling "neighbor_get()" function periodically may not suffice some of our requirements. The first method of "Calling it every time the update message arrives" is more realistic. SDN being program driven, I think we need something like "packet_in_handler" for arrival of BGP Update packets so that applications can handle the same.

Is the Ryu community working to enable/implement such a capability in the near future?.

Thanks
Hadem



On Fri, Jan 19, 2018 at 6:18 AM, Iwase Yusuke <iwase.yusu...@gmail.com <mailto:iwase.yusu...@gmail.com>> wrote:

    Hi Hadem,


        *How can i call my "neighbor_get()"function after the update messages 
are
        received from the neighbor?. can we use any event to achieve this or any
        other
        ways?.*


    Originally, when do you need to call "neighbor_get()" function?
    Every after the update message received? Periodically per N seconds?

    To achieve the former one, unfortunately, now Ryu has no event for such, 
only
    for notifying;
    - best patch changed due to new UPDATE received
    - peer up or down
    
https://github.com/osrg/ryu/blob/8287e3513a780c2dbfe3003f6b632d819a0e792c/ryu/services/protocols/bgp/application.py#L145-L147
    
<https://github.com/osrg/ryu/blob/8287e3513a780c2dbfe3003f6b632d819a0e792c/ryu/services/protocols/bgp/application.py#L145-L147>

    For the latter one, how about spawn a new thread which calls 
"neighbor_get()"
    periodically?


    FYI, "application.py" can be integrated with your own application without
    directly modifying "application.py".
    
http://ryu-iwase.readthedocs.io/en/doc-services_protocols_bgp_application/app/bgp_application.html#integration-with-other-applications
    
<http://ryu-iwase.readthedocs.io/en/doc-services_protocols_bgp_application/app/bgp_application.html#integration-with-other-applications>

    Please note the above link is temporary, because this document is under
    reviewing on Ryu-devel and not yet merged to upstream. When merged, you can 
read
    this document from the "official" Ryu Documentation page.


    Thanks,
    Iwase


    On 2018年01月19日 01:55, Pynbiang Hadem wrote:

        *Hi Iwase,*
        *
        *
        *Yes you are right. The update messages from neighbor (10.0.0.2) was
        received much later as can be seen in the output log file(BGPTest-h1.py)
        attached herewith.*
        *The update message received is as below:*
        /Received msg from ('10.0.0.2', '55930') <<
        
BGPUpdate(len=106,nlri=[],path_attributes=[BGPPathAttributeMpReachNLRI(afi=2,flags=128,length=49,next_hop='::ffff:10.0.0.2',nlri=[LabelledVPNIP6AddrPrefix(addr=([101],
        BGPTwoOctetAsRD(admin=65002,assigned=150,type=0),
        '2001:db8:2::'),length=152)],safi=128,type=14),
        BGPPathAttributeOrigin(flags=64,length=1,type=1,value=2),
        BGPPathAttributeAsPath(flags=64,length=6,type=2,value=[[65002]]),
        BGPPathAttributeMultiExitDisc(flags=128,length=4,type=4,value=100),
        
BGPPathAttributeExtendedCommunities(communities=[BGPTwoOctetAsSpecificExtendedCommunity(as_number=65002,local_administrator=150,subtype=2,type=0)],flags=192,length=8,type=16)],total_path_attribute_len=83,type=2,withdrawn_routes=[],withdrawn_routes_len=0)/
        /Received route with RT ['65002:150'] that is of no interest to any VRFs
        or Peers set(['65001:200', '65001:350', '65001:150', '65001:300',
        '65001:100', '65001:250']). Ignoring paths from this UPDATE:
        
BGPUpdate(len=106,nlri=[],path_attributes=[BGPPathAttributeMpReachNLRI(afi=2,flags=128,length=49,next_hop='::ffff:10.0.0.2',nlri=[LabelledVPNIP6AddrPrefix(addr=([101],
        BGPTwoOctetAsRD(admin=65002,assigned=150,type=0),
        '2001:db8:2::'),length=152)],safi=128,type=14),
        BGPPathAttributeOrigin(flags=64,length=1,type=1,value=2),
        BGPPathAttributeAsPath(flags=64,length=6,type=2,value=[[65002]]),
        BGPPathAttributeMultiExitDisc(flags=128,length=4,type=4,value=100),
        
BGPPathAttributeExtendedCommunities(communities=[BGPTwoOctetAsSpecificExtendedCommunity(as_number=65002,local_administrator=150,subtype=2,type=0)],flags=192,length=8,type=16)],total_path_attribute_len=83,type=2,withdrawn_routes=[],withdrawn_routes_len=0)/
        /Received msg from ('10.0.0.2', '55930') <<
        
BGPUpdate(len=76,nlri=[],path_attributes=[BGPPathAttributeMpReachNLRI(afi=2,flags=128,length=30,next_hop='::ffff:10.0.0.2',nlri=[IP6AddrPrefix(addr='2001:db8:1::',length=64)],safi=1,type=14),
        BGPPathAttributeOrigin(flags=64,length=1,type=1,value=0),
        BGPPathAttributeAsPath(flags=64,length=6,type=2,value=[[65002]]),
        
BGPPathAttributeMultiExitDisc(flags=128,length=4,type=4,value=100)],total_path_attribute_len=53,type=2,withdrawn_routes=[],withdrawn_routes_len=0)
        /

        *How can i call my "neighbor_get()"function after the update messages
        are received from the neighbor?. can we use any event to achieve this or
        any other ways?.*

        Thanks
        Hadem

        On Wed, Jan 17, 2018 at 4:57 AM, Iwase Yusuke <iwase.yusu...@gmail.com
        <mailto:iwase.yusu...@gmail.com> <mailto:iwase.yusu...@gmail.com
        <mailto:iwase.yusu...@gmail.com>>> wrote:

             Hi Hadem,

             In that case, you need to call "neighbor_get()" after connections
        to neighbor(s)
             established and received some routes.
             It seems that Ryu just returns a empty list because Ryu does not
        yet received
             any routes from neighbors.

             Thanks,
             Iwase


             On 2018年01月15日 17:48, Pynbiang Hadem wrote:

                 Hi Iwase,

                 Precisely, i actually wanted to get *adj-RIB-in* information.

                 Is there any problem with my code while trying to achieve 
this?.

                 Thanks
                 Hadem


                 On Mon, Jan 15, 2018 at 5:38 AM, Iwase Yusuke
        <iwase.yusu...@gmail.com <mailto:iwase.yusu...@gmail.com>
                 <mailto:iwase.yusu...@gmail.com
        <mailto:iwase.yusu...@gmail.com>> <mailto:iwase.yusu...@gmail.com
        <mailto:iwase.yusu...@gmail.com>
                 <mailto:iwase.yusu...@gmail.com
        <mailto:iwase.yusu...@gmail.com>>>> wrote:

                      Hi Hadem,

                      It is depending on what you want to get though, you
        attempt to get
                 neighbors
                      information, right?
                      In that case, you should use "neighbors_get()" (plural
        form) instead of
                      "neighbor_get()".
        
http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.neighbors_get
        
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.neighbors_get>
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.neighbors_get
        
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.neighbors_get>>
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.neighbors_get
        
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.neighbors_get>
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.neighbors_get
        
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.neighbors_get>>>

                      With "neighbor_get()" with 
"route_type='received-routes'", Ryu
                 should return the
                      adj-RIB-in information and I guess it is always an empty
        list when
                 starting up
                      (connections are not established with neighbors).


                      Thanks,
                      Iwase


                      On 2018年01月13日 00:59, Pynbiang Hadem wrote:

                          Hi Iwase,

                          I've made the modifications accordingly. *Now i am
        able to see the
                          output for vrfs_get() and rib_get()*. *However there
        is still
                 no output
                          for neighbor_get() . ---output is in 
**BGPTest-output.py*
                          *Pls advice how to get the output for neighbor_get().*
                          *Enclosed herewith: (1) modified bgpapplication1.py & 
(2)
                 BGPTest-output.py*

                          Thanks
                          Hadem





                          On Fri, Jan 12, 2018 at 7:36 AM, Iwase Yusuke
                 <iwase.yusu...@gmail.com <mailto:iwase.yusu...@gmail.com>
        <mailto:iwase.yusu...@gmail.com <mailto:iwase.yusu...@gmail.com>>
                          <mailto:iwase.yusu...@gmail.com
        <mailto:iwase.yusu...@gmail.com>
                 <mailto:iwase.yusu...@gmail.com
        <mailto:iwase.yusu...@gmail.com>>> <mailto:iwase.yusu...@gmail.com
        <mailto:iwase.yusu...@gmail.com>

                 <mailto:iwase.yusu...@gmail.com 
<mailto:iwase.yusu...@gmail.com>>

                          <mailto:iwase.yusu...@gmail.com
        <mailto:iwase.yusu...@gmail.com>
                 <mailto:iwase.yusu...@gmail.com
        <mailto:iwase.yusu...@gmail.com>>>>> wrote:

                               Hi Hadem,

                               First, the return value for each BGPSpeaker's API
        (with
                          format="json") is str
                               type value.
                               Why you need to split them like;
                                    vrf_result = self.speaker.vrfs_get('routes',
        None,
                 'all', 'json')
                                    nowtime = vrf_result[0]  # <--- ?
                                    result = vrf_result[1]   # <--- ?

                               And, please confirm the meaning of each argument 
when
                 calling         BGPSpeaker's
                               APIs.
                               For example, to getting all VRF configurations,
        you need
                 to specify
                          "summary"
                               instead of "routes".
        
http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.vrfs_get
        
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.vrfs_get>
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.vrfs_get
        
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.vrfs_get>>
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.vrfs_get
        
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.vrfs_get>
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.vrfs_get
        
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.vrfs_get>>>
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.vrfs_get
        
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.vrfs_get>
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.vrfs_get
        
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.vrfs_get>>
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.vrfs_get
        
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.vrfs_get>
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.vrfs_get
        
<http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.vrfs_get>>>>

                               Thanks,
                               Iwase


                               On 2018年01月11日 21:55, Pynbiang Hadem wrote:

                                   *Hi,*
                                   *
                                   *
                                   *I am getting blank output for BGPSpeaker
        show_vrf,
                 show_rib,
                                   show_neighbor. The partial output is as 
below:*
                                                  
----------------------------------
                                   /Sending MED Update Message.../
                                   /Send BGP UPDATE Message for changing 
MED[100]/
                                   /API method neighbor.update called with args:
                 {'ip_address':
                          '10.0.0.2',
                                   'changes': {'multi_exit_disc': 100}}/
                                   /on_update_med fired/
                                   /MED value for neigh: Neighbor: 10.0.0.2
        updated to 100/
                                   /Calling get VRFs Information .../
                                   /Shows BGP VRF information in a json format/
                                   /API method operator.show called with args:
        {'params':
                 ['vrf',
                          'routes',
                                   'all'], 'format': 'json'}/
                                   /+++++++++++++++++++++++++++++++/
                                   /{ : Show VRFs /
                                   /+++++++++++++++++++++++++++++++/
                                   /"/
                                   /
                                   /
                                   /Calling SHOW RIB .../
                                   /Shows BGP routing information in a json 
format/
                                   /API method operator.show called with args:
        {'params':
                 ['rib',
                          'all'],
                                   'format': 'json'}/
                                   /+++++++++++++++++++++++++++++++/
                                   /{ : Show rib /
                                   /+++++++++++++++++++++++++++++++/
                                   /"/
                                   /
                                   /
                                   /Calling SHOW Neighbor.../
                                   /Inside Show Neighbor BGP UPDATE Message/
                                   /API method operator.show called with args:
        {'params':
                 ['neighbor',
                                   'received-routes', '10.0.0.2', 'all'],
        'format': 'json'}/
                                   /[]/
                                   /+++++++++++++++++++++++++++++++/
                                   /[ : Show neighbor /
                                   /+++++++++++++++++++++++++++++++/
                                   /]/
------------------------------------------

                                   *I am attaching herewith my BGP application
                          file(bgpapplication1.py). *
                                   *Pls let me know what mistake i have done and
        how to
                 display
                          the above
                                   details.*
                                   *
                                   *
                                   *Thanks*
                                   *Hadem*




------------------------------------------------------------------------------
                                   Check out the vibrant tech community on one
        of the
                 world's most
                                   engaging tech sites, Slashdot.org!
        http://sdm.link/slashdot



                                   
_______________________________________________
                                   Ryu-devel mailing list
        Ryu-devel@lists.sourceforge.net <mailto:Ryu-devel@lists.sourceforge.net>
        <mailto:Ryu-devel@lists.sourceforge.net
        <mailto:Ryu-devel@lists.sourceforge.net>>
                 <mailto:Ryu-devel@lists.sourceforge.net
        <mailto:Ryu-devel@lists.sourceforge.net>
                 <mailto:Ryu-devel@lists.sourceforge.net
        <mailto:Ryu-devel@lists.sourceforge.net>>>
                          <mailto:Ryu-devel@lists.sourceforge.net
        <mailto:Ryu-devel@lists.sourceforge.net>
                 <mailto:Ryu-devel@lists.sourceforge.net
        <mailto:Ryu-devel@lists.sourceforge.net>>
                          <mailto:Ryu-devel@lists.sourceforge.net
        <mailto:Ryu-devel@lists.sourceforge.net>
                 <mailto:Ryu-devel@lists.sourceforge.net
        <mailto:Ryu-devel@lists.sourceforge.net>>>>
        https://lists.sourceforge.net/lists/listinfo/ryu-devel
        <https://lists.sourceforge.net/lists/listinfo/ryu-devel>
                 <https://lists.sourceforge.net/lists/listinfo/ryu-devel
        <https://lists.sourceforge.net/lists/listinfo/ryu-devel>>
<https://lists.sourceforge.net/lists/listinfo/ryu-devel
        <https://lists.sourceforge.net/lists/listinfo/ryu-devel>
                 <https://lists.sourceforge.net/lists/listinfo/ryu-devel
        <https://lists.sourceforge.net/lists/listinfo/ryu-devel>>>
 <https://lists.sourceforge.net/lists/listinfo/ryu-devel
        <https://lists.sourceforge.net/lists/listinfo/ryu-devel>
                 <https://lists.sourceforge.net/lists/listinfo/ryu-devel
        <https://lists.sourceforge.net/lists/listinfo/ryu-devel>>
<https://lists.sourceforge.net/lists/listinfo/ryu-devel
        <https://lists.sourceforge.net/lists/listinfo/ryu-devel>
                 <https://lists.sourceforge.net/lists/listinfo/ryu-devel
        <https://lists.sourceforge.net/lists/listinfo/ryu-devel>>>>




------------------------------------------------------------------------------
                          Check out the vibrant tech community on one of the
        world's most
                          engaging tech sites, Slashdot.org!
        http://sdm.link/slashdot



                          _______________________________________________
                          Ryu-devel mailing list
        Ryu-devel@lists.sourceforge.net <mailto:Ryu-devel@lists.sourceforge.net>
        <mailto:Ryu-devel@lists.sourceforge.net
        <mailto:Ryu-devel@lists.sourceforge.net>>
                 <mailto:Ryu-devel@lists.sourceforge.net
        <mailto:Ryu-devel@lists.sourceforge.net>
                 <mailto:Ryu-devel@lists.sourceforge.net
        <mailto:Ryu-devel@lists.sourceforge.net>>>
        https://lists.sourceforge.net/lists/listinfo/ryu-devel
        <https://lists.sourceforge.net/lists/listinfo/ryu-devel>
                 <https://lists.sourceforge.net/lists/listinfo/ryu-devel
        <https://lists.sourceforge.net/lists/listinfo/ryu-devel>>
<https://lists.sourceforge.net/lists/listinfo/ryu-devel
        <https://lists.sourceforge.net/lists/listinfo/ryu-devel>
                 <https://lists.sourceforge.net/lists/listinfo/ryu-devel
        <https://lists.sourceforge.net/lists/listinfo/ryu-devel>>>




------------------------------------------------------------------------------
                 Check out the vibrant tech community on one of the world's most
                 engaging tech sites, Slashdot.org! http://sdm.link/slashdot



                 _______________________________________________
                 Ryu-devel mailing list
        Ryu-devel@lists.sourceforge.net <mailto:Ryu-devel@lists.sourceforge.net>
        <mailto:Ryu-devel@lists.sourceforge.net
        <mailto:Ryu-devel@lists.sourceforge.net>>
        https://lists.sourceforge.net/lists/listinfo/ryu-devel
        <https://lists.sourceforge.net/lists/listinfo/ryu-devel>
                 <https://lists.sourceforge.net/lists/listinfo/ryu-devel
        <https://lists.sourceforge.net/lists/listinfo/ryu-devel>>




        
------------------------------------------------------------------------------
        Check out the vibrant tech community on one of the world's most
        engaging tech sites, Slashdot.org! http://sdm.link/slashdot



        _______________________________________________
        Ryu-devel mailing list
        Ryu-devel@lists.sourceforge.net <mailto:Ryu-devel@lists.sourceforge.net>
        https://lists.sourceforge.net/lists/listinfo/ryu-devel
        <https://lists.sourceforge.net/lists/listinfo/ryu-devel>




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot



_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

>From 21fd06382b05db4c92c0bba6b7e730e807138ec2 Mon Sep 17 00:00:00 2001
From: IWASE Yusuke <iwase.yusu...@gmail.com>
Date: Mon, 22 Jan 2018 13:15:52 +0900
Subject: [PATCH] BGPSpeaker: Enable to notify adj-RIB-in changed

This patch introduces a new argument "adj_rib_in_change_handler" into
BGPSpeaker and enables to notify adj-RIB-in changed to watchers.

Also this patch enables to "bgp.application.RyuBGPSpeaker" to notify a
new event EventAdjRibInChanged to other Ryu application.

Signed-off-by: IWASE Yusuke <iwase.yusu...@gmail.com>
---
 ryu/services/protocols/bgp/application.py | 35 +++++++++++++++++++++++++++++++
 ryu/services/protocols/bgp/bgpspeaker.py  | 24 +++++++++++++++++++++
 2 files changed, 59 insertions(+)

diff --git a/ryu/services/protocols/bgp/application.py b/ryu/services/protocols/bgp/application.py
index df3e9b9..31cfb5f 100644
--- a/ryu/services/protocols/bgp/application.py
+++ b/ryu/services/protocols/bgp/application.py
@@ -62,6 +62,7 @@ Integration with Other Applications
 following events to other Ryu applications.
 
     - ``EventBestPathChanged``
+    - ``EventAdjRibInChanged``
     - ``EventPeerDown``
     - ``EventPeerUp``
 
@@ -191,6 +192,33 @@ class EventBestPathChanged(EventBase):
         self.is_withdraw = is_withdraw
 
 
+class EventAdjRibInChanged(EventBase):
+    """
+    Event called when any adj-RIB-in path is changed due to UPDATE messages
+    or remote peer's down.
+
+    This event is the wrapper for ``adj_rib_in_change_handler`` of
+    ``bgpspeaker.BGPSpeaker``.
+
+    ``path`` attribute contains an instance of ``info_base.base.Path``
+    subclasses.
+
+    If ``is_withdraw`` attribute is ``True``, ``path`` attribute has the
+    information of the withdraw route.
+
+    ``peer_ip`` is the peer's IP address who sent this path.
+
+    ``peer_as`` is the peer's AS number who sent this path.
+    """
+
+    def __init__(self, path, is_withdraw, peer_ip, peer_as):
+        super(EventAdjRibInChanged, self).__init__()
+        self.path = path
+        self.is_withdraw = is_withdraw
+        self.peer_ip = peer_ip
+        self.peer_as = peer_as
+
+
 class EventPeerDown(EventBase):
     """
     Event called when the session to the remote peer goes down.
@@ -233,6 +261,7 @@ class RyuBGPSpeaker(RyuApp):
     """
     _EVENTS = [
         EventBestPathChanged,
+        EventAdjRibInChanged,
         EventPeerDown,
         EventPeerUp,
     ]
@@ -300,6 +329,8 @@ class RyuBGPSpeaker(RyuApp):
         settings.setdefault(
             'best_path_change_handler', self._notify_best_path_changed_event)
         settings.setdefault(
+            'adj_rib_in_change_handler', self._notify_adj_rib_in_changed_event)
+        settings.setdefault(
             'peer_down_handler', self._notify_peer_down_event)
         settings.setdefault(
             'peer_up_handler', self._notify_peer_up_event)
@@ -330,6 +361,10 @@ class RyuBGPSpeaker(RyuApp):
         ev = EventBestPathChanged(ev.path, ev.is_withdraw)
         self.send_event_to_observers(ev)
 
+    def _notify_adj_rib_in_changed_event(self, ev, peer_ip, peer_as):
+        ev = EventAdjRibInChanged(ev.path, ev.is_withdraw, peer_ip, peer_as)
+        self.send_event_to_observers(ev)
+
     def _notify_peer_down_event(self, remote_ip, remote_as):
         ev = EventPeerDown(remote_ip, remote_as)
         self.send_event_to_observers(ev)
diff --git a/ryu/services/protocols/bgp/bgpspeaker.py b/ryu/services/protocols/bgp/bgpspeaker.py
index 14e5eed..5131c9c 100644
--- a/ryu/services/protocols/bgp/bgpspeaker.py
+++ b/ryu/services/protocols/bgp/bgpspeaker.py
@@ -68,6 +68,7 @@ from ryu.services.protocols.bgp.api.prefix import (
     FLOWSPEC_FAMILY_L2VPN,
     FLOWSPEC_RULES,
     FLOWSPEC_ACTIONS)
+from ryu.services.protocols.bgp.model import ReceivedRoute
 from ryu.services.protocols.bgp.rtconf.common import LOCAL_AS
 from ryu.services.protocols.bgp.rtconf.common import ROUTER_ID
 from ryu.services.protocols.bgp.rtconf.common import CLUSTER_ID
@@ -226,6 +227,7 @@ class BGPSpeaker(object):
                  refresh_stalepath_time=DEFAULT_REFRESH_STALEPATH_TIME,
                  refresh_max_eor_time=DEFAULT_REFRESH_MAX_EOR_TIME,
                  best_path_change_handler=None,
+                 adj_rib_in_change_handler=None,
                  peer_down_handler=None,
                  peer_up_handler=None,
                  ssh_console=False,
@@ -263,6 +265,12 @@ class BGPSpeaker(object):
         peer down. The handler is supposed to take one argument, the
         instance of an EventPrefix class instance.
 
+        ``adj_rib_in_change_handler``, if specified, is called when any
+        adj-RIB-in path is changed due to an update message or remote
+        peer down. The given handler should take three argument, the
+        instance of an EventPrefix class instance, str type peer's IP address
+        and int type peer's AS number.
+
         ``peer_down_handler``, if specified, is called when BGP peering
         session goes down.
 
@@ -315,6 +323,7 @@ class BGPSpeaker(object):
         self._core_start(settings)
         self._init_signal_listeners()
         self._best_path_change_handler = best_path_change_handler
+        self._adj_rib_in_change_handler = adj_rib_in_change_handler
         self._peer_down_handler = peer_down_handler
         self._peer_up_handler = peer_up_handler
         if ssh_console:
@@ -351,6 +360,15 @@ class BGPSpeaker(object):
         if self._best_path_change_handler:
             self._best_path_change_handler(ev)
 
+    def _notify_adj_rib_in_changed(self, peer, route):
+        if not isinstance(route, ReceivedRoute):
+            return
+
+        if self._adj_rib_in_change_handler:
+            self._adj_rib_in_change_handler(
+                EventPrefix(route.path, route.path.is_withdraw),
+                peer.ip_address, peer.remote_as)
+
     def _init_signal_listeners(self):
         CORE_MANAGER.get_core_service()._signal_bus.register_listener(
             BgpSignalBus.BGP_BEST_PATH_CHANGED,
@@ -359,6 +377,12 @@ class BGPSpeaker(object):
                                            info['is_withdraw'])
         )
         CORE_MANAGER.get_core_service()._signal_bus.register_listener(
+            BgpSignalBus.BGP_ADJ_RIB_IN_CHANGED,
+            lambda _, info:
+            self._notify_adj_rib_in_changed(info['peer'],
+                                            info['received_route'])
+        )
+        CORE_MANAGER.get_core_service()._signal_bus.register_listener(
             BgpSignalBus.BGP_ADJ_DOWN,
             lambda _, info:
             self._notify_peer_down(info['peer'])
-- 
2.7.4

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to