packet lib to string: inherits StringifyMixin

Some class inherits stringify.StringifyMixin

and, remove class variable 'tlvs' (not used as class variable
and interferes to string) from lldp.lldp

Signed-off-by: WATANABE Fumitaka <watanabe.fumitaka@nttcom.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
watanabe.fumitaka 2013-08-05 13:07:32 +09:00 committed by FUJITA Tomonori
parent 2a60164b64
commit 87cb024392
6 changed files with 20 additions and 14 deletions

View File

@ -58,6 +58,8 @@ import socket
import struct
from . import packet_base
from ryu.lib import stringify
DHCP_BOOT_REQUEST = 1
DHCP_BOOT_REPLY = 2
@ -190,7 +192,7 @@ class dhcp(packet_base.PacketBase):
self.chaddr, self.sname, self.boot_file, seri_opt)
class options(object):
class options(stringify.StringifyMixin):
"""DHCP (RFC 2132) options encoder/decoder class.
This is used with ryu.lib.packet.dhcp.dhcp.
@ -250,7 +252,7 @@ class options(object):
return seri_opt
class option(object):
class option(stringify.StringifyMixin):
"""DHCP (RFC 2132) options encoder/decoder class.
This is used with ryu.lib.packet.dhcp.dhcp.options.

View File

@ -17,6 +17,7 @@ import struct
from . import packet_base
from . import packet_utils
from ryu.lib import stringify
ICMP_ECHO_REPLY = 0
@ -114,7 +115,7 @@ class icmp(packet_base.PacketBase):
@icmp.register_icmp_type(ICMP_ECHO_REPLY, ICMP_ECHO_REQUEST)
class echo(object):
class echo(stringify.StringifyMixin):
"""ICMP sub encoder/decoder class for Echo and Echo Reply messages.
This is used with ryu.lib.packet.icmp.icmp for
@ -164,7 +165,7 @@ class echo(object):
@icmp.register_icmp_type(ICMP_DEST_UNREACH)
class dest_unreach(object):
class dest_unreach(stringify.StringifyMixin):
"""ICMP sub encoder/decoder class for Destination Unreachable Message.
This is used with ryu.lib.packet.icmp.icmp for
@ -220,7 +221,7 @@ class dest_unreach(object):
@icmp.register_icmp_type(ICMP_TIME_EXCEEDED)
class TimeExceeded(object):
class TimeExceeded(stringify.StringifyMixin):
"""ICMP sub encoder/decoder class for Time Exceeded Message.
This is used with ryu.lib.packet.icmp.icmp for

View File

@ -21,6 +21,7 @@ import binascii
from . import packet_base
from . import packet_utils
from ryu.lib import addrconv
from ryu.lib import stringify
ICMPV6_DST_UNREACH = 1 # dest unreachable, codes:
ICMPV6_PACKET_TOO_BIG = 2 # packet too big
@ -125,7 +126,7 @@ class icmpv6(packet_base.PacketBase):
@icmpv6.register_icmpv6_type(ND_NEIGHBOR_SOLICIT, ND_NEIGHBOR_ADVERT)
class nd_neighbor(object):
class nd_neighbor(stringify.StringifyMixin):
"""ICMPv6 sub encoder/decoder class for Neighbor Solicitation and
Neighbor Advertisement messages. (RFC 4861)
@ -210,7 +211,7 @@ class nd_neighbor(object):
@nd_neighbor.register_nd_option_type(nd_neighbor.ND_OPTION_SLA,
nd_neighbor.ND_OPTION_TLA)
class nd_option_la(object):
class nd_option_la(stringify.StringifyMixin):
"""ICMPv6 sub encoder/decoder class for Neighbor discovery
Source/Target Link-Layer Address Option. (RFC 4861)
@ -263,7 +264,7 @@ class nd_option_la(object):
@icmpv6.register_icmpv6_type(ICMPV6_ECHO_REPLY, ICMPV6_ECHO_REQUEST)
class echo(object):
class echo(stringify.StringifyMixin):
"""ICMPv6 sub encoder/decoder class for Echo Request and Echo Reply
messages.

View File

@ -90,6 +90,7 @@ Control field
import struct
from . import bpdu
from . import packet_base
from ryu.lib import stringify
SAP_BDPU = 0x42
@ -164,7 +165,7 @@ class llc(packet_base.PacketBase):
@llc.register_control_type
class ControlFormatI(object):
class ControlFormatI(stringify.StringifyMixin):
"""LLC sub encoder/decoder class for control I-format field.
An instance has the following attributes at least.
@ -213,7 +214,7 @@ class ControlFormatI(object):
@llc.register_control_type
class ControlFormatS(object):
class ControlFormatS(stringify.StringifyMixin):
"""LLC sub encoder/decoder class for control S-format field.
An instance has the following attributes at least.
@ -265,7 +266,7 @@ class ControlFormatS(object):
@llc.register_control_type
class ControlFormatU(object):
class ControlFormatU(stringify.StringifyMixin):
"""LLC sub encoder/decoder class for control U-format field.
An instance has the following attributes at least.

View File

@ -41,6 +41,7 @@ optional TLV may be inserted in any order
"""
import struct
from ryu.lib import stringify
from ryu.lib.packet import packet_base
@ -70,7 +71,7 @@ LLDP_TLV_MANAGEMENT_ADDRESS = 8 # Management Address
LLDP_TLV_ORGANIZATIONALLY_SPECIFIC = 127 # organizationally Specific TLVs
class LLDPBasicTLV(object):
class LLDPBasicTLV(stringify.StringifyMixin):
_LEN_MIN = 0
_LEN_MAX = 511
tlv_type = None
@ -106,7 +107,6 @@ class LLDPBasicTLV(object):
class lldp(packet_base.PacketBase):
_tlv_parsers = {}
tlvs = []
def __init__(self, tlvs):
super(lldp, self).__init__()

View File

@ -14,9 +14,10 @@
# limitations under the License.
import abc
from ryu.lib import stringify
class PacketBase(object):
class PacketBase(stringify.StringifyMixin):
"""A base class for a protocol (ethernet, ipv4, ...) header."""
__metaclass__ = abc.ABCMeta
_TYPES = {}