Signed-off-by: itoyuichi <[email protected]>
---
ryu/tests/unit/packet/test_icmp.py | 98 ++++++++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+)
diff --git a/ryu/tests/unit/packet/test_icmp.py
b/ryu/tests/unit/packet/test_icmp.py
index f93ed73..1515ead 100644
--- a/ryu/tests/unit/packet/test_icmp.py
+++ b/ryu/tests/unit/packet/test_icmp.py
@@ -16,6 +16,7 @@
import unittest
import inspect
+import json
import logging
import struct
@@ -53,6 +54,18 @@ class Test_icmp(unittest.TestCase):
self.csum_calc = packet_utils.checksum(str(self.buf))
struct.pack_into('!H', self.buf, 2, self.csum_calc)
+ self.jsonstr = '''
+ {
+ "icmp": {
+ "type": 8,
+ "code": 0,
+ "csum": 0,
+ "data": null
+ }
+ }
+ '''
+ self.jsondict = json.loads(self.jsonstr)
+
def setUp_with_echo(self):
self.echo_id = 13379
self.echo_seq = 1
@@ -75,6 +88,25 @@ class Test_icmp(unittest.TestCase):
self.csum_calc = packet_utils.checksum(str(self.buf))
struct.pack_into('!H', self.buf, 2, self.csum_calc)
+ self.jsonstr = '''
+ {
+ "icmp": {
+ "type": 8,
+ "code": 0,
+ "csum": 0,
+ "data": {
+ "echo": {
+ "id": 13379,
+ "seq": 1,
+ "data":
+"MA4JAAAAAAAQERITFBUWFxgZGhscHR4fICEiIyQlJicoKSorLC0uLzAxMjM0NTY3"
+ }
+ }
+ }
+ }
+ '''
+ self.jsondict = json.loads(self.jsonstr)
+
def setUp_with_dest_unreach(self):
self.unreach_mtu = 10
self.unreach_data = 'abc'
@@ -93,6 +125,24 @@ class Test_icmp(unittest.TestCase):
self.csum_calc = packet_utils.checksum(str(self.buf))
struct.pack_into('!H', self.buf, 2, self.csum_calc)
+ self.jsonstr = '''
+ {
+ "icmp": {
+ "type": 3,
+ "code": 1,
+ "csum": 0,
+ "data": {
+ "dest_unreach": {
+ "data_len": 3,
+ "mtu": 10,
+ "data": "YWJj"
+ }
+ }
+ }
+ }
+ '''
+ self.jsondict = json.loads(self.jsonstr)
+
def setUp_with_TimeExceeded(self):
self.te_data = 'abc'
self.te_data_len = len(self.te_data)
@@ -109,6 +159,23 @@ class Test_icmp(unittest.TestCase):
self.csum_calc = packet_utils.checksum(str(self.buf))
struct.pack_into('!H', self.buf, 2, self.csum_calc)
+ self.jsonstr = '''
+ {
+ "icmp": {
+ "type": 11,
+ "code": 0,
+ "csum": 0,
+ "data": {
+ "TimeExceeded": {
+ "data_len": 3,
+ "data": "YWJj"
+ }
+ }
+ }
+ }
+ '''
+ self.jsondict = json.loads(self.jsonstr)
+
def test_init(self):
eq_(self.type_, self.ic.type)
eq_(self.code, self.ic.code)
@@ -217,6 +284,37 @@ class Test_icmp(unittest.TestCase):
self.setUp_with_TimeExceeded()
self.test_to_string()
+ def test_to_jsondict(self):
+ eq_(self.jsondict, self.ic.to_jsondict())
+
+ def test_to_jsondict_with_echo(self):
+ self.setUp_with_echo()
+ self.test_to_jsondict()
+
+ def test_to_jsondict_with_dest_unreach(self):
+ self.setUp_with_dest_unreach()
+ self.test_to_jsondict()
+
+ def test_to_jsondict_with_TimeExceeded(self):
+ self.setUp_with_TimeExceeded()
+ self.test_to_jsondict()
+
+ def test_from_jsondict(self):
+ ic = icmp.icmp.from_jsondict(self.jsondict['icmp'])
+ eq_(str(ic), str(self.ic))
+
+ def test_from_jsondict_with_echo(self):
+ self.setUp_with_echo()
+ self.test_from_jsondict()
+
+ def test_from_jsondict_with_dest_unreach(self):
+ self.setUp_with_dest_unreach()
+ self.test_from_jsondict()
+
+ def test_from_jsondict_with_TimeExceeded(self):
+ self.setUp_with_TimeExceeded()
+ self.test_from_jsondict()
+
class Test_echo(unittest.TestCase):
--
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