On Thu, May 30, 2013 at 02:57:20PM +0900, watanabe.fumitaka wrote:
> Add ICMP sub encoder/decoder class
> for Destination Unreachable Message and Time Exceeded Message.
>
>
> Signed-off-by: WATANABE Fumitaka <[email protected]>
> ---
> ryu/lib/packet/icmp.py | 109
> ++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 109 insertions(+)
>
> diff --git a/ryu/lib/packet/icmp.py b/ryu/lib/packet/icmp.py
> index e42fa40..550a076 100644
> --- a/ryu/lib/packet/icmp.py
> +++ b/ryu/lib/packet/icmp.py
> @@ -24,6 +24,12 @@ ICMP_DEST_UNREACH = 3
> ICMP_SRC_QUENCH = 4
> ICMP_REDIRECT = 5
> ICMP_ECHO_REQUEST = 8
> +ICMP_TIME_EXCEEDED = 11
> +
> +ICMP_ECHO_REPLY_CODE = 0
> +ICMP_HOST_UNREACH_CODE = 1
> +ICMP_PORT_UNREACH_CODE = 3
> +ICMP_TTL_EXPIRED_CODE = 0
>
>
> class icmp(packet_base.PacketBase):
Please update the documentation of data.
data Payload. \
Either a bytearray or ryu.lib.packet.icmp.echo object. \
NOTE: This includes "unused" 16 bits and the following \
"Internet Header + 64 bits of Original Data Datagram" of \
the ICMP header.
> @@ -123,6 +129,7 @@ class echo(object):
> _MIN_LEN = struct.calcsize(_PACK_STR)
>
> def __init__(self, id_, seq, data=None):
> + super(echo, self).__init__()
Thank you for fixing this.
> self.id = id_
> self.seq = seq
> self.data = data
> @@ -146,3 +153,105 @@ class echo(object):
> hdr += self.data
>
> return hdr
> +
> +
> [email protected]_icmp_type(ICMP_DEST_UNREACH)
> +class dest_unreach(object):
> + """ICMP sub encoder/decoder class for Destination Unreachable Message.
> +
> + This is used with ryu.lib.packet.icmp.icmp for
> + ICMP Destination Unreachable Message.
> +
> + An instance has the following attributes at least.
> + Most of them are same to the on-wire counterparts but in host byte order.
> + __init__ takes the correspondig args in this order.
> +
> + ============== ====================
> + Attribute Description
> + ============== ====================
> + data_len data length
> + data Internet Header + leading octets of original datagram
> + ============== ====================
> + """
> +
> + _PACK_STR = '!BBH'
Unused is
Any field
labeled "unused" is reserved for later extensions and must be zero
when sent, but receivers should not use these fields (except to
include them in the checksum).
So unused attribute should not be added. Just drop them.
> + _MIN_LEN = struct.calcsize(_PACK_STR)
> +
> + def __init__(self, data_len=0, data=None):
> + super(dest_unreach, self).__init__()
> + self.unused = 0
unused attribute should be dropped.
> + self.data_len = data_len
> + self.mtu = 0
I'm not sure these two attributes are standard accoding to RFC792. If not,
they need comments and documents.
> + self.data = data
> +
> + @classmethod
> + def parser(cls, buf, offset):
> + (unused, data_len, mtu) = struct.unpack_from(cls._PACK_STR,
> + buf, offset)
> + msg = cls(data_len)
data_len and mtu?
> + offset += cls._MIN_LEN
> +
> + if len(buf) > offset:
> + msg.data = buf[offset:]
> +
> + return msg
> +
> + def serialize(self):
> + hdr = bytearray(struct.pack(dest_unreach._PACK_STR,
> + self.unused, self.data_len, self.mtu))
> +
> + if self.data is not None:
> + hdr += self.data
> +
> + return hdr
> +
> +
> [email protected]_icmp_type(ICMP_TIME_EXCEEDED)
> +class time_exceeded(object):
> + """ICMP sub encoder/decoder class for Time Exceeded Message.
> +
> + This is used with ryu.lib.packet.icmp.icmp for
> + ICMP Time Exceeded Message.
> +
> + An instance has the following attributes at least.
> + Most of them are same to the on-wire counterparts but in host byte order.
> + __init__ takes the correspondig args in this order.
> +
> + ============== ====================
> + Attribute Description
> + ============== ====================
> + data_len data length
> + data Internet Header + leading octets of original datagram
> + ============== ====================
> + """
> +
> + _PACK_STR = '!BBH'
> + _MIN_LEN = struct.calcsize(_PACK_STR)
> +
> + def __init__(self, data_len=0, data=None):
> + super(time_exceeded, self).__init__()
> + self.unused = 0
unused attribute should be dropped.
> + self.data_len = data_len
> + self.mtu = 0
I'm not sure data_len and mtu are standard. If not, they need comments
and documents. Or copy-and-paste error?
> + self.data = data
> +
> + @classmethod
> + def parser(cls, buf, offset):
> + (unused, data_len, mtu) = struct.unpack_from(cls._PACK_STR,
> + buf, offset)
> + msg = cls(data_len)
data_len and mtu?
> + offset += cls._MIN_LEN
> +
> + if len(buf) > offset:
> + msg.data = buf[offset:]
> +
> + return msg
> +
> + def serialize(self):
> + hdr = bytearray(struct.pack(time_exceeded._PACK_STR,
> + self.unused, self.data_len, self.mtu))
> +
> + if self.data is not None:
> + hdr += self.data
> +
> + return hdr
> -- 1.7.10.4
>
>
> ------------------------------------------------------------------------------
> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
> Get 100% visibility into your production application - at no cost.
> Code-level diagnostics for performance bottlenecks with <2% overhead
> Download for free and get started troubleshooting in minutes.
> http://p.sf.net/sfu/appdyn_d2d_ap1
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>
--
yamahata
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite
It's a free troubleshooting tool designed for production
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap2
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel