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

diff --git a/ryu/tests/unit/packet/test_ipv4.py 
b/ryu/tests/unit/packet/test_ipv4.py
index d04c426..1d61320 100644
--- a/ryu/tests/unit/packet/test_ipv4.py
+++ b/ryu/tests/unit/packet/test_ipv4.py
@@ -16,6 +16,7 @@
 # vim: tabstop=4 shiftwidth=4 softtabstop=4

 import unittest
+import json
 import logging
 import struct
 from struct import *
@@ -67,6 +68,28 @@ class Test_ipv4(unittest.TestCase):
     ip = ipv4(version, header_length, tos, total_length, identification,
               flags, offset, ttl, proto, csum, src, dst, option)

+    jsonstr = '''
+    {
+        "ipv4": {
+            "version": 4,
+            "header_length": 15,
+            "tos": 0,
+            "total_length": 79,
+            "identification": 30774,
+            "flags": 4,
+            "offset": 1480,
+            "ttl": 64,
+            "proto": 6,
+            "csum": 44486,
+            "src": "131.151.32.21",
+            "dst": "131.151.32.129",
+            "option":
+            "higAAAABASIAAa4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQ=="
+        }
+    }
+    '''
+    jsondict = json.loads(jsonstr)
+
     def setUp(self):
         pass

@@ -130,3 +153,18 @@ class Test_ipv4(unittest.TestCase):
     def test_malformed_ipv4(self):
         m_short_buf = self.buf[1:ipv4._MIN_LEN]
         ipv4.parser(m_short_buf)
+
+    def test_to_jsondict(self):
+        ip = ipv4(
+            self.version, self.header_length, self.tos, self.total_length,
+            self.identification, self.flags, self.offset, self.ttl,
+            self.proto, self.csum, self.src, self.dst, self.option)
+        eq_(self.jsondict,  ip.to_jsondict())
+
+    def test_from_jsondictt(self):
+        msg1 = ipv4(
+            self.version, self.header_length, self.tos, self.total_length,
+            self.identification, self.flags, self.offset, self.ttl,
+            self.proto, self.csum, self.src, self.dst, self.option)
+        msg2 = ipv4.from_jsondict(self.jsondict['ipv4'])
+        eq_(str(msg1), str(msg2))
-- 
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