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
-
__init__
(pdu_type, mapping, byte_len)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
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
-
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().