although BGP is using internal classes, no class is registered into 
'_class_prefixes'.
therefore, from_jsondict() does not work correctly.
this patch makes from_jsondict() to work correctly by registering internal 
classes into '_class_prefixes'.

examination code:

    from ryu.lib.packet import bgp
    msg1 = bgp.BGPUpdate(withdrawn_routes=[bgp.BGPWithdrawnRoute(length=0, 
addr='192.168.0.1')])
    print msg1
    jsondict = msg1.to_jsondict()
    msg2 = bgp.BGPUpdate.from_jsondict(jsondict['BGPUpdate'])
    print msg2
    print str(msg1) == str(msg2)

before applying this patch:

    
BGPUpdate(len=None,marker='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff',nlri=[],path_attributes=[],total_path_attribute_len=None,type=2,withdrawn_routes=[BGPWithdrawnRoute(addr='192.168.0.1',length=0)],withdrawn_routes_len=None)
    
BGPUpdate(len=None,marker='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff',nlri=[],path_attributes=[],total_path_attribute_len=None,type=2,withdrawn_routes=[{'BGPWithdrawnRoute':
 {'length': 0, 'addr': '192.168.0.1'}}],withdrawn_routes_len=None)
    False

after applying this patch:

    
BGPUpdate(len=None,marker='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff',nlri=[],path_attributes=[],total_path_attribute_len=None,type=2,withdrawn_routes=[BGPWithdrawnRoute(addr='192.168.0.1',length=0)],withdrawn_routes_len=None)
    
BGPUpdate(len=None,marker='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff',nlri=[],path_attributes=[],total_path_attribute_len=None,type=2,withdrawn_routes=[BGPWithdrawnRoute(addr='192.168.0.1',length=0)],withdrawn_routes_len=None)
    True

Signed-off-by: Yuichi Ito <[email protected]>
---
 ryu/lib/packet/bgp.py |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py
index 3f63290..49ded71 100644
--- a/ryu/lib/packet/bgp.py
+++ b/ryu/lib/packet/bgp.py
@@ -668,6 +668,7 @@ class BGPPathAttributeCommunities(_PathAttribute):
 @_PathAttribute.register_type(BGP_ATTR_TYPE_EXTENDED_COMMUNITIES)
 class BGPPathAttributeExtendedCommunities(_PathAttribute):
     _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE
+    _class_prefixes = ['BGP']

     def __init__(self, communities,
                  flags=0, type_=None, length=None):
@@ -799,6 +800,7 @@ class BGPUnknownExtendedCommunity(_ExtendedCommunity):
 class BGPPathAttributeMpReachNLRI(_PathAttribute):
     _VALUE_PACK_STR = '!HBB'  # afi, safi, next hop len
     _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
+    _class_prefixes = ['_BinAddrPrefix']

     def __init__(self, afi, safi, next_hop, nlri,
                  next_hop_len=0, reserved='\0',
@@ -856,6 +858,7 @@ class BGPPathAttributeMpReachNLRI(_PathAttribute):
 class BGPPathAttributeMpUnreachNLRI(_PathAttribute):
     _VALUE_PACK_STR = '!HB'  # afi, safi
     _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
+    _class_prefixes = ['_BinAddrPrefix']

     def __init__(self, afi, safi, withdrawn_routes,
                  flags=0, type_=None, length=None):
@@ -913,6 +916,7 @@ class BGPMessage(packet_base.PacketBase, _TypeDisp):

     _HDR_PACK_STR = '!16sHB'  # marker, len, type
     _HDR_LEN = struct.calcsize(_HDR_PACK_STR)
+    _class_prefixes = ['BGP']

     def __init__(self, type_, len_=None, marker=None):
         if marker is None:
-- 
1.7.10.4


------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to