NOTE: some tests are skipped. the classes 'nd_neighbor', 'nd_router_advert' and 'nd_option_pi' save an argument as the member after bit shift processing.
when a json used for creation of 'nd_neighbor' set 'res' as 7, but a json which the object generated have 'res' as 3758096384 (=7*(2<<29)). Signed-off-by: itoyuichi <[email protected]> --- ryu/tests/unit/packet/test_icmpv6.py | 263 +++++++++++++++++++++++++++++++++- 1 file changed, 261 insertions(+), 2 deletions(-) diff --git a/ryu/tests/unit/packet/test_icmpv6.py b/ryu/tests/unit/packet/test_icmpv6.py index 0a33ca0..b017b57 100644 --- a/ryu/tests/unit/packet/test_icmpv6.py +++ b/ryu/tests/unit/packet/test_icmpv6.py @@ -16,6 +16,7 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 import unittest +import json import logging import struct import inspect @@ -99,6 +100,24 @@ class Test_icmpv6_echo_request(unittest.TestCase): data = '\x01\xc9\xe7\x36\xd3\x39\x06\x00' buf = '\x80\x00\xa5\x72\x76\x20\x00\x00' + jsonstr = ''' + { + "icmpv6": { + "type": 128, + "code": 0, + "csum": 0, + "data": { + "echo": { + "id": 30240, + "seq": 0, + "data": "AcnnNtM5BgA=" + } + } + } + } + ''' + jsondict = json.loads(jsonstr) + def setUp(self): pass @@ -182,6 +201,17 @@ class Test_icmpv6_echo_request(unittest.TestCase): eq_(str(ic), ic_str) eq_(repr(ic), ic_str) + def test_to_jsondict(self): + echo = icmpv6.echo(self.id_, self.seq, self.data) + icmp = icmpv6.icmpv6(self.type_, self.code, 0, echo) + eq_(self.jsondict, icmp.to_jsondict()) + + def test_from_jsondict(self): + echo = icmpv6.echo(self.id_, self.seq, self.data) + msg1 = icmpv6.icmpv6(self.type_, self.code, 0, echo) + msg2 = icmpv6.icmpv6.from_jsondict(self.jsondict['icmpv6']) + eq_(str(msg1), str(msg2)) + class Test_icmpv6_echo_reply(Test_icmpv6_echo_request): def setUp(self): @@ -189,6 +219,24 @@ class Test_icmpv6_echo_reply(Test_icmpv6_echo_request): self.csum = 0xa472 self.buf = '\x81\x00\xa4\x72\x76\x20\x00\x00' + self.jsonstr = ''' + { + "icmpv6": { + "type": 129, + "code": 0, + "csum": 0, + "data": { + "echo": { + "id": 30240, + "seq": 0, + "data": "AcnnNtM5BgA=" + } + } + } + } + ''' + self.jsondict = json.loads(self.jsonstr) + class Test_icmpv6_neighbor_solict(unittest.TestCase): type_ = 135 @@ -206,6 +254,31 @@ class Test_icmpv6_neighbor_solict(unittest.TestCase): src_ipv6 = '3ffe:507:0:1:200:86ff:fe05:80da' dst_ipv6 = '3ffe:501:0:1001::2' + jsonstr = ''' + { + "icmpv6": { + "type": 135, + "code": 0, + "csum": 38189, + "data": { + "nd_neighbor": { + "res": 0, + "dst": "3ffe:507:0:1:200:86ff:fe05:80da", + "type": 1, + "length": 1, + "data": { + "nd_option_la": { + "hw_src": "00:60:97:07:69:ea", + "data": null + } + } + } + } + } + } + ''' + jsondict = json.loads(jsonstr) + def setUp(self): pass @@ -323,6 +396,21 @@ class Test_icmpv6_neighbor_solict(unittest.TestCase): eq_(str(ic), ic_str) eq_(repr(ic), ic_str) + def test_to_jsondict(self): + nd_opt = icmpv6.nd_option_la(self.nd_hw_src) + nd = icmpv6.nd_neighbor( + self.res, self.dst, self.nd_type, self.nd_length, nd_opt) + ic = icmpv6.icmpv6(self.type_, self.code, self.csum, nd) + eq_(self.jsondict, ic.to_jsondict()) + + def test_from_jsondict(self): + nd_opt = icmpv6.nd_option_la(self.nd_hw_src) + nd = icmpv6.nd_neighbor( + self.res, self.dst, self.nd_type, self.nd_length, nd_opt) + msg1 = icmpv6.icmpv6(self.type_, self.code, self.csum, nd) + msg2 = icmpv6.icmpv6.from_jsondict(self.jsondict['icmpv6']) + eq_(str(msg1), str(msg2)) + class Test_icmpv6_neighbor_advert(Test_icmpv6_neighbor_solict): def setUp(self): @@ -339,8 +427,48 @@ class Test_icmpv6_neighbor_advert(Test_icmpv6_neighbor_solict): + '\x3f\xfe\x05\x07\x00\x00\x00\x01' \ + '\x02\x60\x97\xff\xfe\x07\x69\xea' - -class Test_icmpv6_router_solict(unittest.TestCase): + self.jsonstr = ''' + { + "icmpv6": { + "type": 136, + "code": 0, + "csum": 47290, + "data": { + "nd_neighbor": { + "res": 7, + "dst": "3ffe:507:0:1:260:97ff:fe07:69ea", + "type": 2, + "length": 1, + "data": { + "nd_option_la": { + "hw_src": "00:60:97:07:69:ea", + "data": null + } + } + } + } + } + } + ''' + self.jsondict = json.loads(self.jsonstr) + + def test_to_jsondict(self): + nd_opt = icmpv6.nd_option_la(self.nd_hw_src) + nd = icmpv6.nd_neighbor( + self.res, self.dst, self.nd_type, self.nd_length, nd_opt) + ic = icmpv6.icmpv6(self.type_, self.code, self.csum, nd) + # the public member 'res' differs from the argument 'res' of + # nd_neighbor.__init__() because using bit shift. + LOG.info("SKIP [Test_icmpv6_neighbor_advert.test_to_jsondict]") + LOG.debug("self.jsondict:") + LOG.debug(self.jsondict) + LOG.debug("ic.to_jsondict():") + LOG.debug(ic.to_jsondict()) + raise SkipTest("TODO: make reversible nd_neighbor.") + eq_(self.jsondict, ic.to_jsondict()) + + +class Test_icmpv6_router_solicit(unittest.TestCase): type_ = 133 code = 0 csum = 0x97d9 @@ -353,6 +481,30 @@ class Test_icmpv6_router_solict(unittest.TestCase): src_ipv6 = '3ffe:507:0:1:200:86ff:fe05:80da' dst_ipv6 = '3ffe:501:0:1001::2' + jsonstr = ''' + { + "icmpv6": { + "type": 133, + "code": 0, + "csum": 0, + "data": { + "nd_router_solicit": { + "res": 0, + "type": 1, + "length": 1, + "data": { + "nd_option_la": { + "hw_src": "12:2d:a5:6d:bc:0f", + "data": null + } + } + } + } + } + } + ''' + jsondict = json.loads(jsonstr) + def setUp(self): pass @@ -464,3 +616,110 @@ class Test_icmpv6_router_solict(unittest.TestCase): eq_(str(ic), ic_str) eq_(repr(ic), ic_str) + + def test_to_jsondict(self): + nd_opt = icmpv6.nd_option_la(self.nd_hw_src) + rs = icmpv6.nd_router_solicit(self.res, self.nd_type, self.nd_length, + nd_opt) + ic = icmpv6.icmpv6(self.type_, self.code, 0, rs) + eq_(self.jsondict, ic.to_jsondict()) + + def test_from_jsondict(self): + nd_opt = icmpv6.nd_option_la(self.nd_hw_src) + rs = icmpv6.nd_router_solicit(self.res, self.nd_type, self.nd_length, + nd_opt) + msg1 = icmpv6.icmpv6(self.type_, self.code, 0, rs) + msg2 = icmpv6.icmpv6.from_jsondict(self.jsondict['icmpv6']) + eq_(str(msg1), str(msg2)) + + +class Test_icmpv6_router_advert(unittest.TestCase): + type_ = 134 + code = 0 + csum = 0xc4fe + ch_l = 64 + res = 0 + rou_l = 1800 + rea_t = 0 + ret_t = 0 + nd_type = 3 + nd_length = 4 + nd_pi_pl = 40 + nd_pi_res1 = 6 + nd_pi_val_l = 259200 + nd_pi_pre_l = 604800 + nd_pi_res2 = 0 + nd_pi_prefix = '2001:db8:0:1::' + data = '\x00\x00\x00\x00\x01\x01\x12\x2d\xa5\x6d\xbc\x0f' + buf = '\x85\x00\x97\xd9' + src_ipv6 = '3ffe:507:0:1:200:86ff:fe05:80da' + dst_ipv6 = '3ffe:501:0:1001::2' + + jsonstr = ''' + { + "icmpv6": { + "type": 134, + "code": 0, + "csum": 0, + "data": { + "nd_router_advert": { + "ch_l": 64, + "res": 0, + "rou_l": 1800, + "rea_t": 0, + "ret_t": 0, + "type": 3, + "length": 4, + "data": { + "nd_option_pi": { + "pl": 40, + "res1": 6, + "val_l": 259200, + "pre_l": 604800, + "res2": 0, + "prefix": "2001:db8:0:1::" + } + } + } + } + } + } + ''' + jsondict = json.loads(jsonstr) + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_to_jsondict(self): + nd_opt = icmpv6.nd_option_pi( + self.nd_pi_pl, self.nd_pi_res1, self.nd_pi_val_l, + self.nd_pi_pre_l, self.nd_pi_res2, self.nd_pi_prefix) + rs = icmpv6.nd_router_advert( + self.ch_l, self.res, self.rou_l, self.rea_t, self.ret_t, + self.nd_type, self.nd_length, nd_opt) + ic = icmpv6.icmpv6(self.type_, self.code, 0, rs) + # the public member 'res' differs from the argument 'res' of + # nd_router_advert.__init__() because using bit shift. + # nd_option_pi, too. + LOG.info("SKIP [Test_icmpv6_router_advert.test_to_jsondict]") + LOG.debug("self.jsondict:") + LOG.debug(self.jsondict) + LOG.debug("ic.to_jsondict():") + LOG.debug(ic.to_jsondict()) + raise SkipTest( + "TODO: make reversible nd_router_advert and nd_option_pi.") + eq_(self.jsondict, ic.to_jsondict()) + + def test_from_jsondict(self): + nd_opt = icmpv6.nd_option_pi( + self.nd_pi_pl, self.nd_pi_res1, self.nd_pi_val_l, + self.nd_pi_pre_l, self.nd_pi_res2, self.nd_pi_prefix) + rs = icmpv6.nd_router_advert( + self.ch_l, self.res, self.rou_l, self.rea_t, self.ret_t, + self.nd_type, self.nd_length, nd_opt) + msg1 = icmpv6.icmpv6(self.type_, self.code, 0, rs) + msg2 = icmpv6.icmpv6.from_jsondict(self.jsondict['icmpv6']) + 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
