NOTE: test_to_jsondict() is skipped.

the class 'PortDescription' requires an argument 'port_description' at 
__init__(),
but the class have the property 'port_description' that use 'tlv_info'
instead of the member 'port_description'.
the classes 'SystemName' and 'SystemDescription' are the same.

all classes that inherit LLDPBasicTLV have some public members which do not 
relate to arguments of __init__().

a json used for creation of the object does not need 'typelen' and 'len',
but a json which the object generated include them.


Signed-off-by: itoyuichi <[email protected]>
---
 ryu/tests/unit/packet/test_lldp.py |  127 ++++++++++++++++++++++++++++++++++++
 1 file changed, 127 insertions(+)

diff --git a/ryu/tests/unit/packet/test_lldp.py 
b/ryu/tests/unit/packet/test_lldp.py
index 60e93b0..be1c18e 100644
--- a/ryu/tests/unit/packet/test_lldp.py
+++ b/ryu/tests/unit/packet/test_lldp.py
@@ -16,9 +16,11 @@
 # vim: tabstop=4 shiftwidth=4 softtabstop=4

 import unittest
+import json
 import logging
 import struct
 import inspect
+from nose.plugins.skip import SkipTest
 from nose.tools import ok_, eq_, nottest

 from ryu.ofproto import ether
@@ -472,3 +474,128 @@ class TestLLDPOptionalTLV(unittest.TestCase):

         eq_(str(lldp_pkt), lldp_str)
         eq_(repr(lldp_pkt), lldp_str)
+
+    def _make_json(self):
+        src = '00:01:30:f9:ad:a0'
+        tlv_chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
+                                        chassis_id=addrconv.mac.
+                                        text_to_bin(src))
+        tlv_port_id = lldp.PortID(subtype=lldp.PortID.SUB_INTERFACE_NAME,
+                                  port_id='1/1')
+        tlv_ttl = lldp.TTL(ttl=120)
+        tlv_port_description = lldp.PortDescription(
+            port_description='Summit300-48-Port 1001\x00')
+        tlv_system_name = lldp.SystemName(system_name='Summit300-48\x00')
+        tlv_system_description = lldp.SystemDescription(
+            system_description='Summit300-48 - Version 7.4e.1 (Build 5) '
+                               + 'by Release_Master 05/27/05 04:53:11\x00')
+        tlv_system_capabilities = lldp.SystemCapabilities(
+            subtype=lldp.ChassisID.SUB_CHASSIS_COMPONENT,
+            system_cap=0x14,
+            enabled_cap=0x14)
+        tlv_management_address = lldp.ManagementAddress(
+            addr_subtype=0x06, addr='\x00\x01\x30\xf9\xad\xa0',
+            intf_subtype=0x02, intf_num=1001,
+            oid='')
+        tlv_organizationally_specific = lldp.OrganizationallySpecific(
+            oui='\x00\x12\x0f', subtype=0x02, info='\x07\x01\x00')
+        tlv_end = lldp.End()
+        # Sets are not able to encode to json, so that Lists are used.
+        tlvs = [tlv_chassis_id, tlv_port_id, tlv_ttl, tlv_port_description,
+                tlv_system_name, tlv_system_description,
+                tlv_system_capabilities, tlv_management_address,
+                tlv_organizationally_specific, tlv_end]
+        self.lldp_pkt = lldp.lldp(tlvs)
+        jsonstr = '''
+        {
+            "lldp": {
+                "tlvs": [
+                    {
+                        "ChassisID": {
+                            "subtype": 4,
+                            "chassis_id": "AAEw+a2g"
+                        }
+                    },
+                    {
+                        "PortID": {
+                            "subtype": 5,
+                            "port_id": "1/1"
+                        }
+                    },
+                    {
+                        "TTL": {
+                            "ttl": 120
+                        }
+                    },
+                    {
+                        "PortDescription": {
+                            "port_description":
+                                "U3VtbWl0MzAwLTQ4LVBvcnQgMTAwMQA="
+                        }
+                    },
+                    {
+                        "SystemName": {
+                            "system_name": "U3VtbWl0MzAwLTQ4AA=="
+                        }
+                    },
+                    {
+                        "SystemDescription": {
+                            "system_description":
+"U3VtbWl0MzAwLTQ4IC0gVmVyc2lvbiA3LjRlLjEgKEJ1aWxkIDUpIGJ5IFJlbGVhc2VfT\
+WFzdGVyIDA1LzI3LzA1IDA0OjUzOjExAA=="
+                        }
+                    },
+                    {
+                        "SystemCapabilities": {
+                            "subtype": 1,
+                            "system_cap": 20,
+                            "enabled_cap": 20
+                        }
+                    },
+                    {
+                        "ManagementAddress": {
+                            "addr_subtype": 6,
+                            "addr": "AAEw+a2g",
+                            "intf_subtype": 2,
+                            "intf_num": 1001,
+                            "oid": ""
+                        }
+                    },
+                    {
+                        "OrganizationallySpecific": {
+                            "oui": "ABIP",
+                            "subtype": 2,
+                            "info": "BwEA"
+                        }
+                    },
+                    {
+                        "End": {
+                        }
+                    }
+                ]
+            }
+        }
+        '''
+        self.jsondict = json.loads(jsonstr)
+
+    def test_to_jsondict(self):
+        self._make_json()
+        # PortDescription.port_description is renamed to tlv_info.
+        # SystemName.system_name is renamed to tlv_info.
+        # SystemDescription.system_description is  renamed to tlv_info.
+        # any TLVs have typelen and len as public members which do not
+        # relate to arguments of __init__().
+        LOG.info("SKIP [TestLLDPOptionalTLV.test_to_jsondict]")
+        LOG.debug("self.jsondict:")
+        LOG.debug(self.jsondict)
+        LOG.debug("self.lldp_pkt.to_jsondict():")
+        LOG.debug(self.lldp_pkt.to_jsondict())
+        raise SkipTest("TODO: make reversible any TLVs.")
+        eq_(self.jsondict, self.lldp_pkt.to_jsondict())
+
+    def test_from_jsondict(self):
+        # PortDescription, SystemName, and SystemDescription contain
+        # a control code '\x00' which is not permitted in jsonstring.
+        self._make_json()
+        msg = lldp.lldp.from_jsondict(self.jsondict['lldp'])
+        eq_(str(msg), str(self.lldp_pkt))
-- 
1.7.10.4


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to