although LLDP 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 lldp
    msg1 = lldp.lldp([lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS, 
chassis_id='\x00\x00\x00\x00\x00\x00')])
    print msg1
    jsondict = msg1.to_jsondict()
    msg2 = lldp.lldp.from_jsondict(jsondict['lldp'])
    print msg2
    print str(msg1) == str(msg2)

before applying this patch:

    
lldp(tlvs=[ChassisID(chassis_id='\x00\x00\x00\x00\x00\x00',len=7,subtype=4,typelen=519)])
    lldp(tlvs=[{'ChassisID': {'subtype': 4, 'typelen': 519, 'chassis_id': 
'\x00\x00\x00\x00\x00\x00', 'len': 7}}])
    False

after applying this patch:

    
lldp(tlvs=[ChassisID(chassis_id='\x00\x00\x00\x00\x00\x00',len=7,subtype=4,typelen=519)])
    
lldp(tlvs=[ChassisID(chassis_id='\x00\x00\x00\x00\x00\x00',len=7,subtype=4,typelen=519)])
    True

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

diff --git a/ryu/lib/packet/lldp.py b/ryu/lib/packet/lldp.py
index 41dc297..71b9829 100644
--- a/ryu/lib/packet/lldp.py
+++ b/ryu/lib/packet/lldp.py
@@ -41,7 +41,6 @@ optional TLV may be inserted in any order
 """

 import struct
-from ryu.lib import stringify
 from ryu.lib.packet import packet_base


@@ -71,7 +70,7 @@ LLDP_TLV_MANAGEMENT_ADDRESS = 8         # Management Address
 LLDP_TLV_ORGANIZATIONALLY_SPECIFIC = 127  # organizationally Specific TLVs


-class LLDPBasicTLV(stringify.StringifyMixin):
+class LLDPBasicTLV(packet_base.StringifyMixin):
     _LEN_MIN = 0
     _LEN_MAX = 511
     tlv_type = None
@@ -482,3 +481,6 @@ class OrganizationallySpecific(LLDPBasicTLV):

     def serialize(self):
         return struct.pack('!H3sB', self.typelen, self.oui, self.subtype)
+
+
+lldp.set_classes(lldp._tlv_parsers)
-- 
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

Reply via email to