summaryrefslogtreecommitdiffhomepage
path: root/ryu/lib/packet/icmpv6.py
diff options
context:
space:
mode:
Diffstat (limited to 'ryu/lib/packet/icmpv6.py')
-rw-r--r--ryu/lib/packet/icmpv6.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/ryu/lib/packet/icmpv6.py b/ryu/lib/packet/icmpv6.py
index fe94c77f..53d5ec3a 100644
--- a/ryu/lib/packet/icmpv6.py
+++ b/ryu/lib/packet/icmpv6.py
@@ -112,7 +112,7 @@ class icmpv6(packet_base.PacketBase):
return cls
return _register_icmpv6_type
- def __init__(self, type_=0, code=0, csum=0, data=None):
+ def __init__(self, type_=0, code=0, csum=0, data=b''):
super(icmpv6, self).__init__()
self.type_ = type_
self.code = code
@@ -137,8 +137,9 @@ class icmpv6(packet_base.PacketBase):
hdr = bytearray(struct.pack(icmpv6._PACK_STR, self.type_,
self.code, self.csum))
- if self.data is not None:
+ if self.data:
if self.type_ in icmpv6._ICMPV6_TYPES:
+ assert isinstance(self.data, _ICMPv6Payload)
hdr += self.data.serialize()
else:
hdr += self.data
@@ -149,14 +150,18 @@ class icmpv6(packet_base.PacketBase):
return hdr
def __len__(self):
- length = self._MIN_LEN
- if self.data is not None:
- length += len(self.data)
- return length
+ return self._MIN_LEN + len(self.data)
+
+
+@six.add_metaclass(abc.ABCMeta)
+class _ICMPv6Payload(stringify.StringifyMixin):
+ """
+ Base class for the payload of ICMPv6 packet.
+ """
@icmpv6.register_icmpv6_type(ND_NEIGHBOR_SOLICIT, ND_NEIGHBOR_ADVERT)
-class nd_neighbor(stringify.StringifyMixin):
+class nd_neighbor(_ICMPv6Payload):
"""ICMPv6 sub encoder/decoder class for Neighbor Solicitation and
Neighbor Advertisement messages. (RFC 4861)
@@ -237,7 +242,7 @@ class nd_neighbor(stringify.StringifyMixin):
@icmpv6.register_icmpv6_type(ND_ROUTER_SOLICIT)
-class nd_router_solicit(stringify.StringifyMixin):
+class nd_router_solicit(_ICMPv6Payload):
"""ICMPv6 sub encoder/decoder class for Router Solicitation messages.
(RFC 4861)
@@ -308,7 +313,7 @@ class nd_router_solicit(stringify.StringifyMixin):
@icmpv6.register_icmpv6_type(ND_ROUTER_ADVERT)
-class nd_router_advert(stringify.StringifyMixin):
+class nd_router_advert(_ICMPv6Payload):
"""ICMPv6 sub encoder/decoder class for Router Advertisement messages.
(RFC 4861)
@@ -619,7 +624,7 @@ class nd_option_pi(nd_option):
@icmpv6.register_icmpv6_type(ICMPV6_ECHO_REPLY, ICMPV6_ECHO_REQUEST)
-class echo(stringify.StringifyMixin):
+class echo(_ICMPv6Payload):
"""ICMPv6 sub encoder/decoder class for Echo Request and Echo Reply
messages.
@@ -675,7 +680,7 @@ class echo(stringify.StringifyMixin):
@icmpv6.register_icmpv6_type(
MLD_LISTENER_QUERY, MLD_LISTENER_REPOR, MLD_LISTENER_DONE)
-class mld(stringify.StringifyMixin):
+class mld(_ICMPv6Payload):
"""ICMPv6 sub encoder/decoder class for MLD Lister Query,
MLD Listener Report, and MLD Listener Done messages. (RFC 2710)