diff options
author | Yuichi Ito <ito.yuichi0@gmail.com> | 2013-11-06 17:14:27 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-11-08 10:44:28 +0900 |
commit | b32dbed5c1503cf879da7fda271acadef1d7acb0 (patch) | |
tree | 8873038e7107f1f9f5c7825239ad4c5cfe47cf0e | |
parent | c062520b757d1acb65b95266b92290669811fd04 (diff) |
packet lib: icmpv6: change the timing of bit shift
As well as the automatic calculation, do bit shift when encoding.
Signed-off-by: Yuichi Ito <ito.yuichi0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/lib/packet/icmpv6.py | 23 | ||||
-rw-r--r-- | 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 4da7fa2c..25605a60 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 81d74456..c24839ca 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) |