Signed-off-by: itoyuichi <[email protected]>
---
ryu/tests/unit/packet/test_ipv6.py | 161 ++++++++++++++++++++++++++++++++++++
1 file changed, 161 insertions(+)
diff --git a/ryu/tests/unit/packet/test_ipv6.py
b/ryu/tests/unit/packet/test_ipv6.py
index 42c5523..8ca7bda 100644
--- a/ryu/tests/unit/packet/test_ipv6.py
+++ b/ryu/tests/unit/packet/test_ipv6.py
@@ -132,6 +132,65 @@ class Test_ipv6(unittest.TestCase):
addrconv.ipv6.text_to_bin(self.dst))
self.buf += self.fragment.serialize()
+ def setUp_with_auth(self):
+ self.auth_size = 4
+ self.auth_spi = 256
+ self.auth_seq = 1
+ self.auth_data = '\xa0\xe7\xf8\xab\xf9\x69\x1a\x8b\xf3\x9f\x7c\xae'
+ self.auth = ipv6.auth(
+ self.auth_size, self.auth_spi, self.auth_seq, self.auth_data)
+ self.ext_hdrs = [self.auth]
+ self.payload_length += len(self.auth)
+ self.ip = ipv6.ipv6(
+ self.version, self.traffic_class, self.flow_label,
+ self.payload_length, self.nxt, self.hop_limit, self.src,
+ self.dst, self.ext_hdrs)
+ self.auth.nxt = self.nxt
+ self.nxt = self.auth.TYPE
+ self.buf = struct.pack(
+ ipv6.ipv6._PACK_STR, self.v_tc_flow,
+ self.payload_length, self.nxt, self.hop_limit,
+ addrconv.ipv6.text_to_bin(self.src),
+ addrconv.ipv6.text_to_bin(self.dst))
+ self.buf += self.auth.serialize()
+
+ def setUp_with_multi_headers(self):
+ self.opt1_type = 5
+ self.opt1_len = 2
+ self.opt1_data = '\x00\x00'
+ self.opt2_type = 1
+ self.opt2_len = 0
+ self.opt2_data = None
+ self.options = [
+ ipv6.option(self.opt1_type, self.opt1_len, self.opt1_data),
+ ipv6.option(self.opt2_type, self.opt2_len, self.opt2_data),
+ ]
+ self.hop_opts_size = 0
+ self.hop_opts = ipv6.hop_opts(self.hop_opts_size, self.options)
+ self.auth_size = 4
+ self.auth_spi = 256
+ self.auth_seq = 1
+ self.auth_data = '\xa0\xe7\xf8\xab\xf9\x69\x1a\x8b\xf3\x9f\x7c\xae'
+ self.auth = ipv6.auth(
+ self.auth_size, self.auth_spi, self.auth_seq, self.auth_data)
+ self.ext_hdrs = [self.hop_opts, self.auth]
+ self.payload_length += len(self.hop_opts) + len(self.auth)
+ self.ip = ipv6.ipv6(
+ self.version, self.traffic_class, self.flow_label,
+ self.payload_length, self.nxt, self.hop_limit, self.src,
+ self.dst, self.ext_hdrs)
+ self.hop_opts.nxt = self.nxt
+ self.nxt = self.hop_opts.TYPE
+ self.auth.nxt = self.hop_opts.nxt
+ self.hop_opts.nxt = self.auth.TYPE
+ self.buf = struct.pack(
+ ipv6.ipv6._PACK_STR, self.v_tc_flow,
+ self.payload_length, self.nxt, self.hop_limit,
+ addrconv.ipv6.text_to_bin(self.src),
+ addrconv.ipv6.text_to_bin(self.dst))
+ self.buf += self.hop_opts.serialize()
+ self.buf += self.auth.serialize()
+
def tearDown(self):
pass
@@ -158,6 +217,14 @@ class Test_ipv6(unittest.TestCase):
self.setUp_with_fragment()
self.test_init()
+ def test_init_with_auth(self):
+ self.setUp_with_auth()
+ self.test_init()
+
+ def test_init_with_multi_headers(self):
+ self.setUp_with_multi_headers()
+ self.test_init()
+
def test_parser(self):
_res = self.ip.parser(str(self.buf))
if type(_res) is tuple:
@@ -187,6 +254,14 @@ class Test_ipv6(unittest.TestCase):
self.setUp_with_fragment()
self.test_parser()
+ def test_parser_with_auth(self):
+ self.setUp_with_auth()
+ self.test_parser()
+
+ def test_parser_with_multi_headers(self):
+ self.setUp_with_multi_headers()
+ self.test_parser()
+
def test_serialize(self):
data = bytearray()
prev = None
@@ -231,6 +306,30 @@ class Test_ipv6(unittest.TestCase):
fragment = ipv6.fragment.parser(str(buf[ipv6.ipv6._MIN_LEN:]))
eq_(repr(self.fragment), repr(fragment))
+ def test_serialize_with_auth(self):
+ self.setUp_with_auth()
+ self.test_serialize()
+
+ data = bytearray()
+ prev = None
+ buf = self.ip.serialize(data, prev)
+ auth = ipv6.auth.parser(str(buf[ipv6.ipv6._MIN_LEN:]))
+ eq_(repr(self.auth), repr(auth))
+
+ def test_serialize_with_multi_headers(self):
+ self.setUp_with_multi_headers()
+ self.test_serialize()
+
+ data = bytearray()
+ prev = None
+ buf = self.ip.serialize(data, prev)
+ offset = ipv6.ipv6._MIN_LEN
+ hop_opts = ipv6.hop_opts.parser(str(buf[offset:]))
+ offset += len(hop_opts)
+ auth = ipv6.auth.parser(str(buf[offset:]))
+ eq_(repr(self.hop_opts), repr(hop_opts))
+ eq_(repr(self.auth), repr(auth))
+
def test_to_string(self):
ipv6_values = {'version': self.version,
'traffic_class': self.traffic_class,
@@ -261,6 +360,14 @@ class Test_ipv6(unittest.TestCase):
self.setUp_with_fragment()
self.test_to_string()
+ def test_to_string_with_auth(self):
+ self.setUp_with_auth()
+ self.test_to_string()
+
+ def test_to_string_with_multi_headers(self):
+ self.setUp_with_multi_headers()
+ self.test_to_string()
+
def test_len(self):
eq_(len(self.ip), 40)
@@ -276,6 +383,14 @@ class Test_ipv6(unittest.TestCase):
self.setUp_with_fragment()
eq_(len(self.ip), 40 + len(self.fragment))
+ def test_len_with_auth(self):
+ self.setUp_with_auth()
+ eq_(len(self.ip), 40 + len(self.auth))
+
+ def test_len_with_multi_headers(self):
+ self.setUp_with_multi_headers()
+ eq_(len(self.ip), 40 + len(self.hop_opts) + len(self.auth))
+
class Test_hop_opts(unittest.TestCase):
@@ -533,3 +648,49 @@ class Test_fragment(unittest.TestCase):
def test_len(self):
eq_(8, len(self.fragment))
+
+
+class Test_auth(unittest.TestCase):
+
+ def setUp(self):
+ self.nxt = 0
+ self.size = 4
+ self.spi = 256
+ self.seq = 1
+ self.data = '\x21\xd3\xa9\x5c\x5f\xfd\x4d\x18\x46\x22\xb9\xf8'
+ self.auth = ipv6.auth(self.size, self.spi, self.seq, self.data)
+ self.auth.set_nxt(self.nxt)
+ self.form = '!BB2xII12s'
+ self.buf = struct.pack(self.form, self.nxt, self.size, self.spi,
+ self.seq, self.data)
+
+ def test_init(self):
+ eq_(self.nxt, self.auth.nxt)
+ eq_(self.size, self.auth.size)
+ eq_(self.spi, self.auth.spi)
+ eq_(self.seq, self.auth.seq)
+ eq_(self.data, self.auth.data)
+
+ def test_parser(self):
+ _res = ipv6.auth.parser(self.buf)
+ if type(_res) is tuple:
+ res = _res[0]
+ else:
+ res = _res
+ eq_(self.nxt, res.nxt)
+ eq_(self.size, res.size)
+ eq_(self.spi, res.spi)
+ eq_(self.seq, res.seq)
+ eq_(self.data, res.data)
+
+ def test_serialize(self):
+ buf = self.auth.serialize()
+ res = struct.unpack_from(self.form, str(buf))
+ eq_(self.nxt, res[0])
+ eq_(self.size, res[1])
+ eq_(self.spi, res[2])
+ eq_(self.seq, res[3])
+ eq_(self.data, res[4])
+
+ def test_len(self):
+ eq_((4 - 1) * 8, len(self.auth))
--
1.7.10.4
------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13.
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel