As well as the automatic calculation, do bit shift when encoding.
Signed-off-by: Yuichi Ito <[email protected]>
---
ryu/lib/packet/icmpv6.py | 23 +++++++++++++----------
ryu/tests/unit/packet/test_icmpv6.py | 4 ++--
2 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/ryu/lib/packet/icmpv6.py b/ryu/lib/packet/icmpv6.py
index 4da7fa2..25605a6 100644
--- a/ryu/lib/packet/icmpv6.py
+++ b/ryu/lib/packet/icmpv6.py
@@ -181,7 +181,7 @@ class nd_neighbor(stringify.StringifyMixin):
return _register_nd_option_type
def __init__(self, res, dst, type_=None, length=None, data=None):
- self.res = res << 29
+ self.res = res
self.dst = dst
self.type_ = type_
self.length = length
@@ -204,9 +204,10 @@ class nd_neighbor(stringify.StringifyMixin):
return msg
def serialize(self):
- hdr = bytearray(struct.pack(nd_neighbor._PACK_STR, self.res,
- addrconv.ipv6.text_to_bin(self.dst)))
-
+ res = self.res << 29
+ hdr = bytearray(struct.pack(
+ nd_neighbor._PACK_STR, res,
+ addrconv.ipv6.text_to_bin(self.dst)))
if self.type_ is not None:
hdr += bytearray(struct.pack('!BB', self.type_, self.length))
if self.type_ in nd_neighbor._ND_OPTION_TYPES:
@@ -350,7 +351,7 @@ class nd_router_advert(stringify.StringifyMixin):
def __init__(self, ch_l, res, rou_l, rea_t, ret_t, type_=None, length=None,
data=None):
self.ch_l = ch_l
- self.res = res << 6
+ self.res = res
self.rou_l = rou_l
self.rea_t = rea_t
self.ret_t = ret_t
@@ -385,9 +386,10 @@ class nd_router_advert(stringify.StringifyMixin):
return msg
def serialize(self):
- hdr = bytearray(struct.pack(nd_router_advert._PACK_STR, self.ch_l,
- self.res, self.rou_l, self.rea_t,
- self.ret_t))
+ res = self.res << 6
+ hdr = bytearray(struct.pack(
+ nd_router_advert._PACK_STR, self.ch_l, res, self.rou_l,
+ self.rea_t, self.ret_t))
if self.type_ is not None:
for i in range(len(self.type_)):
hdr += bytearray(struct.pack('!BB', self.type_[i],
@@ -492,7 +494,7 @@ class nd_option_pi(stringify.StringifyMixin):
def __init__(self, pl, res1, val_l, pre_l, res2, prefix):
self.pl = pl
- self.res1 = res1 << 5
+ self.res1 = res1
self.val_l = val_l
self.pre_l = pre_l
self.res2 = res2
@@ -510,7 +512,8 @@ class nd_option_pi(stringify.StringifyMixin):
return msg
def serialize(self):
- hdr = bytearray(struct.pack(self._PACK_STR, self.pl, self.res1,
+ res1 = self.res1 << 5
+ hdr = bytearray(struct.pack(self._PACK_STR, self.pl, res1,
self.val_l, self.pre_l, self.res2,
addrconv.ipv6.text_to_bin(self.prefix)))
diff --git a/ryu/tests/unit/packet/test_icmpv6.py
b/ryu/tests/unit/packet/test_icmpv6.py
index 81d7445..c24839c 100644
--- a/ryu/tests/unit/packet/test_icmpv6.py
+++ b/ryu/tests/unit/packet/test_icmpv6.py
@@ -214,7 +214,7 @@ class Test_icmpv6_neighbor_solicit(unittest.TestCase):
def test_init(self):
nd = icmpv6.nd_neighbor(self.res, self.dst)
- eq_(nd.res >> 29, self.res)
+ eq_(nd.res, self.res)
eq_(nd.dst, self.dst)
eq_(nd.type_, None)
eq_(nd.length, None)
@@ -227,7 +227,7 @@ class Test_icmpv6_neighbor_solicit(unittest.TestCase):
eq_(msg.type_, self.type_)
eq_(msg.code, self.code)
eq_(msg.csum, self.csum)
- eq_(msg.data.res >> 29, self.res)
+ eq_(msg.data.res, self.res)
eq_(addrconv.ipv6.text_to_bin(msg.data.dst),
addrconv.ipv6.text_to_bin(self.dst))
eq_(n, None)
--
1.7.10.4
------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel