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 | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py
index 3f63290..d298c21 100644
--- a/ryu/lib/packet/bgp.py
+++ b/ryu/lib/packet/bgp.py
@@ -29,7 +29,6 @@ import abc
import struct
from ryu.ofproto.ofproto_parser import msg_pack_into
-from ryu.lib.stringify import StringifyMixin
from ryu.lib.packet import packet_base
from ryu.lib.packet import stream_parser
from ryu.lib import addrconv
@@ -94,7 +93,7 @@ def pad(bin, len_):
return bin + (len_ - len(bin)) * '\0'
-class _AddrPrefix(StringifyMixin):
+class _AddrPrefix(packet_base.StringifyMixin):
__metaclass__ = abc.ABCMeta
_PACK_STR = '!B' # length
@@ -226,7 +225,7 @@ class _TypeDisp(object):
return cls._REV_TYPES[targ_cls]
-class _OptParam(StringifyMixin, _TypeDisp, _Value):
+class _OptParam(packet_base.StringifyMixin, _TypeDisp, _Value):
_PACK_STR = '!BB' # type, length
def __init__(self, type_, value=None, length=None):
@@ -382,7 +381,7 @@ class BGPWithdrawnRoute(_IPAddrPrefix):
pass
-class _PathAttribute(StringifyMixin, _TypeDisp, _Value):
+class _PathAttribute(packet_base.StringifyMixin, _TypeDisp, _Value):
_PACK_STR = '!BB' # flags, type
_PACK_STR_LEN = '!B' # length
_PACK_STR_EXT_LEN = '!H' # length w/ BGP_ATTR_FLAG_EXTENDED_LENGTH
@@ -668,6 +667,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):
@@ -695,7 +695,7 @@ class BGPPathAttributeExtendedCommunities(_PathAttribute):
return buf
-class _ExtendedCommunity(StringifyMixin, _TypeDisp, _Value):
+class _ExtendedCommunity(packet_base.StringifyMixin, _TypeDisp, _Value):
_PACK_STR = '!B7s' # type high (+ type low) + value
IANA_AUTHORITY = 0x80
TRANSITIVE = 0x40
@@ -799,6 +799,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 +857,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 +915,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
------------------------------------------------------------------------------
Sponsored by Intel(R) XDK
Develop, test and display web and hybrid apps with a single code base.
Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel