Files
storage_fresco/tpdu.py
2019-05-23 13:36:01 +00:00

68 lines
1.9 KiB
Python
Executable File

#!/usr/bin/python
__author__ = "Daniel Egger"
__date__ = "22 March 2002"
__email__ = "egger@interearth.com"
__version__ = "$Revision: 1.1 $"[11:-2]
# Packet types
TPDU_CC = 0xd # Connection reply
TPDU_CR = 0xe # Connection request
TPDU_DT = 0xf # Datapacket transfer
# Packet parameters
PARM_ACKTIME = 0x85 # Acknowledge time
PARM_RER = 0x86 # Residual error rate
PARM_PRIORITY = 0x87 # Priority
PARM_TRANSITDELAY = 0x88 # Transit delay
PARM_THROUGHPUT = 0x89 # Troughput
PARM_SUBSEQNUM = 0x8a # Subsequence number
PARM_REASSTIME = 0x8b # Reassignment time
PARM_FLOWCTRLCON = 0x8c # Flow control confirmation
PARM_SIZE = 0xc0 # Size of the TPDU
PARM_SRCTSAP = 0xc1 # The calling TSAP
PARM_DSTTSAP = 0xc2 # The called TSAP
PARM_CHECKSUM = 0xc3 # Checksum
PARM_VERSION = 0xc4 # Version number
PARM_PROTECTION = 0xc5 # Protection
PARM_OPTIONS = 0xc6 # Additional option selection
PARM_ALTERNATIVE = 0xc7 # Alternative protocol classes
class TPDU:
len = 0
code = 0
def type (self):
"""
Return type hexadecimal type of the TPDU. This function is
common for all TPDUs.
"""
return self.code
def __len__ (self):
"""
Return the calcuclated length of the TPDU. The value is
always WITHOUT the coded type, add 1 to it if in doubt.
"""
return self.len
def __repr__ (self):
"""
Print a representation of the TPDU. Use this method via
`-pair to transfer it over the wire. This will just return
the header data and not the real data!
"""
# Note that the data is not included in the length
return "%c%c" % (2, self.code << 4, self.number)
def __str__ (self):
"""
Return a readable and quite verbose overview of the TPDU instance.
Use this for debugging purposes or if you're just curious.
"""
string = DT_STRING % (self.len, self.number, self.data)
return string