diff options
author | Yuichi Ito <ito.yuichi0@gmail.com> | 2013-12-12 15:31:21 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-12-12 18:21:50 +0900 |
commit | 9b0c24c6dffaeae9f49df999900a91964943b0ed (patch) | |
tree | 25c9ae3426727eb676b545468118da4ad55b87a9 | |
parent | 3f9a902198dce92f9044f22f34a1b89ab618e29e (diff) |
packet lib: bgp: fix reversibility about json
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 <ito.yuichi0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/lib/packet/bgp.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py index 3f63290d..49ded71f 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: |