Protocol Data Units

Created on 27.04.2018

@author: klauspopp@gmx.de

class moddy.lib.pdu.Pdu(pdu_type, mapping, byte_len)[source]

Representation of a protocol data unit

The Pdu is represented as a dictionary, containing the modelled protocol pdu fields. The additional member ‘_byte_len’ represents the real byte length of all pdu fields

dict={ 'm1': m1value, 'm2': m2value }, _byte_len=10

Pdus can be nested.

Parameters
  • pdu_type (str) – A string describing the type of the Pdu (without ‘Pdu’), e.g. ‘Eth’

  • mapping (dict) – dictionary with member:value pairs, value can be a sub-Pdu

  • byte_len – top level byte Len - subPdus len will be added

__init__(pdu_type, mapping, byte_len)[source]

Initialize self. See help(type(self)) for accurate signature.

byte_len()[source]

Return the length of the Pdu in bytes, including all its nested PDUs

dump()[source]

Return a string as __repr()__, but also dump sub-pdus in separated, intended lines, e.g.:

IpPdu(1220) ihl=14 flags=0 src=192.1.1.2 dst=192.1.1.8
payld=RawPdu(1000) payld2=RawPdu(200)
    payld:RawPdu(1000) raw=IPPAYLOAD
    payld2:RawPdu(200) raw=AnotherPayld
fill_up(n_bytes)[source]

Fill top level PDU up, so it has a byte_len of n_bytes if PDU already larger, raise Attribute error

classmethod is_pdu(obj)[source]

Check if obj is a Pdu or a subclass of Pdu

split_to_fragments(pdu_type, max_frag_byte_len)[source]

Split the Pdu into fragments and return list of fragments Each fragment is represented as a Pdu

Pdu( "<orgtype>Frag", { 'fr': (<offset of fragment>,
<len of fragment>), 'org'=[<original Pdu>], fraglen )

Note: the ‘org’ member is transferred with every fragment. It is enclosed in a list, so that it is not included in the fragment’s byte length.

The PduDefragmenter class can be used to defragment the fragments

Parameters
  • pdu_type (string) – pdu_type to set for fragments

  • max_frag_byte_len (int) – maximum bytes per fragment

Return list

list of fragments

class moddy.lib.pdu.PduDefragmenter[source]

Class to defragment a PDU that has been fragmented with split_to_fragments().

Create an instance of this class and add all received fragments with add_fragment(). Fragments may be received in any order.

Whether the defragmentation is complete, can be checked by calling the_pdu() or defrag_complete_info().

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

add_fragment(frag)[source]

Add a received fragment

defrag_complete_info()[source]

Check if defragmentation complete.

Return string

None if complete or string with info with first missing frag

the_pdu()[source]

Return the complete defragmented PDU. If fragments are missing, return None.

moddy.lib.pdu.empty_pdu(pdu_type)[source]

return a empty PDU