Signed-off-by: itoyuichi <[email protected]>
---
ryu/tests/unit/packet/test_ipv6.py | 247 ++++++++++++++++++++++++++++++++++++
1 file changed, 247 insertions(+)
diff --git a/ryu/tests/unit/packet/test_ipv6.py
b/ryu/tests/unit/packet/test_ipv6.py
index 0810086..3eb8a0b 100644
--- a/ryu/tests/unit/packet/test_ipv6.py
+++ b/ryu/tests/unit/packet/test_ipv6.py
@@ -17,6 +17,7 @@
import unittest
import logging
import inspect
+import json
import struct
from nose.tools import *
@@ -55,6 +56,23 @@ class Test_ipv6(unittest.TestCase):
addrconv.ipv6.text_to_bin(self.src),
addrconv.ipv6.text_to_bin(self.dst))
+ self.jsonstr = '''
+ {
+ "ipv6": {
+ "version": 6,
+ "traffic_class": 0,
+ "flow_label": 0,
+ "payload_length": 817,
+ "nxt": 6,
+ "hop_limit": 128,
+ "src": "2002:4637:d5d3::4637:d5d3",
+ "dst": "2001:4860:0:2001::68",
+ "ext_hdrs": []
+ }
+ }
+ '''
+ self.jsondict = json.loads(self.jsonstr)
+
def setUp_with_hop_opts(self):
self.opt1_type = 5
self.opt1_len = 2
@@ -84,6 +102,46 @@ class Test_ipv6(unittest.TestCase):
addrconv.ipv6.text_to_bin(self.dst))
self.buf += self.hop_opts.serialize()
+ self.jsonstr = '''
+ {
+ "ipv6": {
+ "version": 6,
+ "traffic_class": 0,
+ "flow_label": 0,
+ "payload_length": 825,
+ "nxt": 0,
+ "hop_limit": 128,
+ "src": "2002:4637:d5d3::4637:d5d3",
+ "dst": "2001:4860:0:2001::68",
+ "ext_hdrs": [
+ {
+ "hop_opts": {
+ "nxt": 6,
+ "size": 0,
+ "data": [
+ {
+ "option": {
+ "type": 5,
+ "len": 2,
+ "data": "AAA="
+ }
+ },
+ {
+ "option": {
+ "type": 1,
+ "len": 0,
+ "data": null
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ }
+ '''
+ self.jsondict = json.loads(self.jsonstr)
+
def setUp_with_dst_opts(self):
self.opt1_type = 5
self.opt1_len = 2
@@ -113,6 +171,46 @@ class Test_ipv6(unittest.TestCase):
addrconv.ipv6.text_to_bin(self.dst))
self.buf += self.dst_opts.serialize()
+ self.jsonstr = '''
+ {
+ "ipv6": {
+ "version": 6,
+ "traffic_class": 0,
+ "flow_label": 0,
+ "payload_length": 825,
+ "nxt": 60,
+ "hop_limit": 128,
+ "src": "2002:4637:d5d3::4637:d5d3",
+ "dst": "2001:4860:0:2001::68",
+ "ext_hdrs": [
+ {
+ "dst_opts": {
+ "nxt": 6,
+ "size": 0,
+ "data": [
+ {
+ "option": {
+ "type": 5,
+ "len": 2,
+ "data": "AAA="
+ }
+ },
+ {
+ "option": {
+ "type": 1,
+ "len": 0,
+ "data": null
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ }
+ '''
+ self.jsondict = json.loads(self.jsonstr)
+
def setUp_with_fragment(self):
self.fragment_nxt = 6
self.fragment_offset = 50
@@ -135,6 +233,32 @@ class Test_ipv6(unittest.TestCase):
addrconv.ipv6.text_to_bin(self.dst))
self.buf += self.fragment.serialize()
+ self.jsonstr = '''
+ {
+ "ipv6": {
+ "version": 6,
+ "traffic_class": 0,
+ "flow_label": 0,
+ "payload_length": 825,
+ "nxt": 44,
+ "hop_limit": 128,
+ "src": "2002:4637:d5d3::4637:d5d3",
+ "dst": "2001:4860:0:2001::68",
+ "ext_hdrs": [
+ {
+ "fragment": {
+ "nxt": 6,
+ "offset": 50,
+ "more": 1,
+ "id": 123
+ }
+ }
+ ]
+ }
+ }
+ '''
+ self.jsondict = json.loads(self.jsonstr)
+
def setUp_with_auth(self):
self.auth_nxt = 6
self.auth_size = 4
@@ -158,6 +282,33 @@ class Test_ipv6(unittest.TestCase):
addrconv.ipv6.text_to_bin(self.dst))
self.buf += self.auth.serialize()
+ self.jsonstr = '''
+ {
+ "ipv6": {
+ "version": 6,
+ "traffic_class": 0,
+ "flow_label": 0,
+ "payload_length": 841,
+ "nxt": 51,
+ "hop_limit": 128,
+ "src": "2002:4637:d5d3::4637:d5d3",
+ "dst": "2001:4860:0:2001::68",
+ "ext_hdrs": [
+ {
+ "auth": {
+ "nxt": 6,
+ "size": 4,
+ "spi": 256,
+ "seq": 1,
+ "data": "oOf4q/lpGovzn3yu"
+ }
+ }
+ ]
+ }
+ }
+ '''
+ self.jsondict = json.loads(self.jsonstr)
+
def setUp_with_multi_headers(self):
self.opt1_type = 5
self.opt1_len = 2
@@ -196,6 +347,55 @@ class Test_ipv6(unittest.TestCase):
self.buf += self.hop_opts.serialize()
self.buf += self.auth.serialize()
+ self.jsonstr = '''
+ {
+ "ipv6": {
+ "version": 6,
+ "traffic_class": 0,
+ "flow_label": 0,
+ "payload_length": 849,
+ "nxt": 0,
+ "hop_limit": 128,
+ "src": "2002:4637:d5d3::4637:d5d3",
+ "dst": "2001:4860:0:2001::68",
+ "ext_hdrs": [
+ {
+ "hop_opts": {
+ "nxt": 51,
+ "size": 0,
+ "data": [
+ {
+ "option": {
+ "type": 5,
+ "len": 2,
+ "data": "AAA="
+ }
+ },
+ {
+ "option": {
+ "type": 1,
+ "len": 0,
+ "data": null
+ }
+ }
+ ]
+ }
+ },
+ {
+ "auth": {
+ "nxt": 6,
+ "size": 4,
+ "spi": 256,
+ "seq": 1,
+ "data": "oOf4q/lpGovzn3yu"
+ }
+ }
+ ]
+ }
+ }
+ '''
+ self.jsondict = json.loads(self.jsonstr)
+
def tearDown(self):
pass
@@ -373,6 +573,53 @@ class Test_ipv6(unittest.TestCase):
self.setUp_with_multi_headers()
self.test_to_string()
+ def test_to_jsondict(self):
+ eq_(self.jsondict, self.ip.to_jsondict())
+
+ def test_to_jsondict_with_hop_opts(self):
+ self.setUp_with_hop_opts()
+ self.test_to_jsondict()
+
+ def test_to_jsondict_with_dst_opts(self):
+ self.setUp_with_dst_opts()
+ self.test_to_jsondict()
+
+ def test_to_jsondict_with_fragment(self):
+ self.setUp_with_fragment()
+ self.test_to_jsondict()
+
+ def test_to_jsondict_with_auth(self):
+ self.setUp_with_auth()
+ self.test_to_jsondict()
+
+ def test_to_jsondict_with_multi_headers(self):
+ self.setUp_with_multi_headers()
+ self.test_to_jsondict()
+
+ def test_from_jsondict(self):
+ ip = ipv6.ipv6.from_jsondict(self.jsondict['ipv6'])
+ eq_(str(ip), str(self.ip))
+
+ def test_from_jsondict_with_hop_opts(self):
+ self.setUp_with_hop_opts()
+ self.test_from_jsondict()
+
+ def test_from_jsondict_with_dst_opts(self):
+ self.setUp_with_dst_opts()
+ self.test_from_jsondict()
+
+ def test_from_jsondict_with_fragment(self):
+ self.setUp_with_fragment()
+ self.test_from_jsondict()
+
+ def test_from_jsondict_with_auth(self):
+ self.setUp_with_auth()
+ self.test_from_jsondict()
+
+ def test_from_jsondict_with_multi_headers(self):
+ self.setUp_with_multi_headers()
+ self.test_from_jsondict()
+
def test_len(self):
eq_(len(self.ip), 40)
--
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