CFDP Package
Package Contents
The CFDP module contains the low level components to create the CFDP packets as specfied in the standard. It also contains basic enumerations and abstractions which were considered useful and generic enough to be included. These abstractions can be used as a foundation to build more complex classes and handlers to perform full CFDP end-to-end transfers.
These components can not be found in this library, but you can find a reference implementation of high level handlers in the tmtccmd library.
You can find a usage example including multiple packet data units used to perform a full unacknowledged file transfer on the example page.
- class spacepackets.cfdp.CfdpLv(value: bytes | bytearray)
Bases:
objectThis class encapsulates CFDP Length-Value (LV) fields.
- Raises:
ValueError – If value is invalid and serilization is enabled or if length of bytearray is too large.
- classmethod unpack(raw_bytes: bytes | bytearray) CfdpLv
Parses LV field at the start of the given bytearray
- Raises:
ValueError – Invalid length found
- class spacepackets.cfdp.CfdpTlv(tlv_type: TlvType, value: bytes | bytearray)
Bases:
AbstractTlvBaseEncapsulates the CFDP Type-Length-Value (TLV) format. For more information, refer to CCSDS 727.0-B-5 p.77
Constructor for TLV field.
- Raises:
ValueError – Length invalid or value length not equal to specified length.
- MINIMAL_LEN = 2
- classmethod unpack(data: bytes | bytearray) CfdpTlv
Parses LV field at the start of the given bytearray
- Parameters:
data
- Raises:
BytesTooShortError – Length of raw data too short.
ValueError – Invalid format of the raw bytearray or type field invalid
- Returns:
- class spacepackets.cfdp.ChecksumType(value)
Bases:
IntEnumAn enumeration.
- CRC_32 = 3
- CRC_32C = 2
- CRC_32_PROXIMITY_1 = 1
- MODULAR = 0
- NULL_CHECKSUM = 15
- class spacepackets.cfdp.ConditionCode(value)
Bases:
IntEnumAn enumeration.
- CANCEL_REQUEST_RECEIVED = 15
- CHECK_LIMIT_REACHED = 10
- FILESTORE_REJECTION = 4
- FILE_CHECKSUM_FAILURE = 5
- FILE_SIZE_ERROR = 6
- INACTIVITY_DETECTED = 8
- INVALID_TRANSMISSION_MODE = 3
- KEEP_ALIVE_LIMIT_REACHED = 2
- NAK_LIMIT_REACHED = 7
- NO_CONDITION_FIELD = -1
- NO_ERROR = 0
- POSITIVE_ACK_LIMIT_REACHED = 1
- SUSPEND_REQUEST_RECEIVED = 14
- UNSUPPORTED_CHECKSUM_TYPE = 11
- class spacepackets.cfdp.DeliveryCode(value)
Bases:
IntEnumAn enumeration.
- DATA_COMPLETE = 0
- DATA_INCOMPLETE = 1
- class spacepackets.cfdp.Direction(value)
Bases:
IntEnumThis is used for PDU forwarding
- TOWARDS_RECEIVER = 0
- TOWARDS_SENDER = 1
- class spacepackets.cfdp.DirectiveType(value)
Bases:
IntEnumAn enumeration.
- ACK_PDU = 6
- EOF_PDU = 4
- FINISHED_PDU = 5
- KEEP_ALIVE_PDU = 12
- METADATA_PDU = 7
- NAK_PDU = 8
- NONE = 10
- PROMPT_PDU = 9
- class spacepackets.cfdp.EntityIdTlv(entity_id: bytes)
Bases:
AbstractTlvBaseThis helper class has a
__eq__()implementation which only compares the numerical value of the entity IDs- TLV_TYPE = 6
- classmethod from_tlv(cfdp_tlv: CfdpTlv) EntityIdTlv
- classmethod unpack(data: bytes | bytearray) EntityIdTlv
- class spacepackets.cfdp.FaultHandlerCode(value)
Bases:
IntEnumAn enumeration.
- ABANDON_TRANSACTION = 4
- IGNORE_ERROR = 3
- NOTICE_OF_CANCELLATION = 1
- NOTICE_OF_SUSPENSION = 2
- class spacepackets.cfdp.FaultHandlerOverrideTlv(condition_code: ConditionCode, handler_code: FaultHandlerCode)
Bases:
AbstractTlvBase- TLV_TYPE = 4
- classmethod from_tlv(cfdp_tlv: CfdpTlv) FaultHandlerOverrideTlv
- classmethod unpack(data: bytes) FaultHandlerOverrideTlv
- class spacepackets.cfdp.FileStatus(value)
Bases:
IntEnumAn enumeration.
- DISCARDED_DELIBERATELY = 0
- DISCARDED_FILESTORE_REJECTION = 1
- FILE_RETAINED = 2
- FILE_STATUS_UNREPORTED = 3
- class spacepackets.cfdp.FileStoreRequestTlv(action_code: FilestoreActionCode, first_file_name: str, second_file_name: str = '')
Bases:
FileStoreRequestBase,AbstractTlvBase- TLV_TYPE = 0
- classmethod from_tlv(cfdp_tlv: CfdpTlv) FileStoreRequestTlv
- classmethod unpack(data: bytes) FileStoreRequestTlv
- class spacepackets.cfdp.FileStoreResponseTlv(action_code: FilestoreActionCode, status_code: FilestoreResponseStatusCode, first_file_name: str, second_file_name: str = '', filestore_msg: None | CfdpLv = None)
Bases:
FileStoreRequestBase,AbstractTlvBase- TLV_TYPE = 1
- classmethod from_tlv(cfdp_tlv: CfdpTlv) FileStoreResponseTlv
- classmethod unpack(data: bytes | bytearray) FileStoreResponseTlv
- class spacepackets.cfdp.FilestoreActionCode(value)
Bases:
IntEnumAll filestore action codes as specified in CCSDS 727.0-B-5 p.86 SNP: Second name present, SNN: Second name not present
- APPEND_FILE_SNP = 3
- CREATE_DIR_SNN = 5
- CREATE_FILE_SNM = 0
- DELETE_FILE_SNN = 1
- DENY_DIR_SNN = 8
- DENY_FILE_SMM = 7
- REMOVE_DIR_SNN = 6
- RENAME_FILE_SNP = 2
- REPLACE_FILE_SNP = 4
- class spacepackets.cfdp.FilestoreResponseStatusCode(value)
Bases:
IntEnumFile store response status codes. First four bits are the action code, last four bits the status code
- APPEND_FILE_NAME_ONE_NOT_EXISTS = 49
- APPEND_FILE_NAME_TWO_NOT_EXISTS = 50
- APPEND_FROM_DATA_FILE_NOT_EXISTS = 2
- APPEND_NOT_ALLOWED = 51
- APPEND_NOT_PERFORMED = 63
- APPEND_SUCCESS = 48
- CREATE_DIR_CAN_NOT_BE_CREATED = 81
- CREATE_DIR_NOT_PERFORMED = 95
- CREATE_DIR_SUCCESS = 80
- CREATE_NOT_ALLOWED = 1
- CREATE_NOT_PERFORMED = 15
- CREATE_SUCCESS = 0
- DELETE_FILE_DOES_NOT_EXIST = 17
- DELETE_NOT_ALLOWED = 31
- DELETE_SUCCESS = 16
- DENY_DIR_DEL_NOT_ALLOWED = 130
- DENY_DIR_DEL_NOT_PERFORMED = 143
- DENY_DIR_DEL_SUCCESS = 128
- DENY_FILE_DEL_NOT_ALLOWED = 114
- DENY_FILE_DEL_NOT_PERFORMED = 127
- DENY_FILE_DEL_SUCCESS = 112
- INVALID = -1
- NOT_PERFORMED = 15
- REMOVE_DIR_DOES_NOT_EXIST = 97
- REMOVE_DIR_NOT_ALLOWED = 98
- REMOVE_DIR_NOT_PERFORMED = 111
- REMOVE_DIR_SUCCESS = 96
- RENAME_NEW_FILE_DOES_EXIST = 34
- RENAME_NOT_ALLOWED = 35
- RENAME_NOT_PERFORMED = 47
- RENAME_OLD_FILE_DOES_NOT_EXIST = 33
- RENAME_SUCCESS = 32
- REPLACE_FILE_NAME_ONE_TO_BE_REPLACED_DOES_NOT_EXIST = 65
- REPLACE_FILE_NAME_TWO_REPLACE_SOURCE_NOT_EXIST = 66
- REPLACE_NOT_ALLOWED = 67
- REPLACE_NOT_PERFORMED = 79
- REPLACE_SUCCESS = 64
- SUCCESS = 0
- class spacepackets.cfdp.FinishedParams(condition_code: 'ConditionCode', delivery_code: 'DeliveryCode', file_status: 'FileStatus', file_store_responses: 'list[FileStoreResponseTlv]' = <factory>, fault_location: 'EntityIdTlv | None' = None)
Bases:
object- condition_code: ConditionCode
- delivery_code: DeliveryCode
- classmethod empty() FinishedParams
- fault_location: EntityIdTlv | None = None
- file_status: FileStatus
- file_store_responses: list[FileStoreResponseTlv]
- classmethod success_params() FinishedParams
Generate the finished parameters to generate a full success
FinishedPduPDU.
- class spacepackets.cfdp.FlowLabelTlv(flow_label: bytes)
Bases:
AbstractTlvBase- TLV_TYPE = 5
- classmethod from_tlv(cfdp_tlv: CfdpTlv) FlowLabelTlv
- classmethod unpack(data: bytes) FlowLabelTlv
- exception spacepackets.cfdp.InvalidCrcError(crc16: int, message: str | None = None)
Bases:
Exception
- class spacepackets.cfdp.MessageToUserTlv(msg: bytes)
Bases:
AbstractTlvBaseMessage to User TLV implementation as specified in CCSDS 727.0-B-5 5.4.3
- TLV_TYPE = 2
- classmethod from_tlv(cfdp_tlv: CfdpTlv) MessageToUserTlv
- to_reserved_msg_tlv() ReservedCfdpMessage | None
Attempt to convert to a reserved CFDP message. Please note that this operation will fail if the message if not a reserved CFDP message and will then return None. This method is especially useful to have access to the more specialized
ReservedCfdpMessageAPI.
- classmethod unpack(data: bytes | bytearray) MessageToUserTlv
- class spacepackets.cfdp.PduConfig(source_entity_id: UnsignedByteField, dest_entity_id: UnsignedByteField, transaction_seq_num: UnsignedByteField, trans_mode: TransmissionMode, file_flag: LargeFileFlag = LargeFileFlag.NORMAL, crc_flag: CrcFlag = CrcFlag.NO_CRC, direction: Direction = Direction.TOWARDS_RECEIVER, seg_ctrl: SegmentationControl = SegmentationControl.NO_RECORD_BOUNDARIES_PRESERVATION)
Bases:
objectCommon configuration fields for a PDU.
- dest_entity_id: UnsignedByteField
- classmethod empty() PduConfig
Empty PDU configuration which is not valid for usage because the contained unsigned byte fields are empty (sequence number and both entity IDs)
- file_flag: LargeFileFlag = 0
- seg_ctrl: SegmentationControl = 0
- source_entity_id: UnsignedByteField
- trans_mode: TransmissionMode
- transaction_seq_num: UnsignedByteField
- class spacepackets.cfdp.PduFactory
Bases:
objectHelper class to generate PDUs and retrieve PDU information from a raw bytestream
- static from_raw(data: bytes | bytearray) AbstractFileDirectiveBase | AbstractPduBase | None
- static pdu_directive_type(data: bytes | bytearray) DirectiveType | None
Retrieve the PDU directive type from a raw bytestream.
- Raises:
ValueError – Invalid directive type.
- Returns:
None, if the PDU in the given bytestream is not a file directive, otherwise the directive.
- class spacepackets.cfdp.PduHolder(pdu: AbstractFileDirectiveBase | AbstractPduBase | None)
Bases:
objectHelper type to store arbitrary PDU types and cast them to a concrete PDU type conveniently
- property base: AbstractFileDirectiveBase | AbstractPduBase | None
Deprecated since version 0.19.0: use packet member instead
- property pdu_directive_type: DirectiveType | None
If the contained type is not a PDU file directive, returns None. Otherwise, returns the directive type
- to_file_data_pdu() FileDataPdu
- to_finished_pdu() FinishedPdu
- to_keep_alive_pdu() KeepAlivePdu
- to_metadata_pdu() MetadataPdu
- class spacepackets.cfdp.PduType(value)
Bases:
IntEnumAn enumeration.
- FILE_DATA = 1
- FILE_DIRECTIVE = 0
- class spacepackets.cfdp.SegmentMetadataFlag(value)
Bases:
IntEnumAways 0 and ignored for File Directive PDUs (CCSDS 727.0-B-5 p.75)
- NOT_PRESENT = 0
- PRESENT = 1
- class spacepackets.cfdp.SegmentationControl(value)
Bases:
IntEnumAlways 0 and ignored for File Directive PDUs (CCSDS 727.0-B-5 p.75)
- NO_RECORD_BOUNDARIES_PRESERVATION = 0
- RECORD_BOUNDARIES_PRESERVATION = 1
- class spacepackets.cfdp.TlvHolder(tlv: AbstractTlvBase | None)
Bases:
object- to_entity_id() EntityIdTlv
- to_fault_handler_override() FaultHandlerOverrideTlv
- to_flow_label() FlowLabelTlv
- to_fs_request() FileStoreRequestTlv
- to_fs_response() FileStoreResponseTlv
- to_msg_to_user() MessageToUserTlv
- class spacepackets.cfdp.TlvType(value)
Bases:
IntEnumAll available TLV types
- ENTITY_ID = 6
- FAULT_HANDLER = 4
- FILESTORE_REQUEST = 0
- FILESTORE_RESPONSE = 1
- FLOW_LABEL = 5
- MESSAGE_TO_USER = 2
- exception spacepackets.cfdp.TlvTypeMissmatchError(found: TlvType, expected: TlvType)
Bases:
Exception
- class spacepackets.cfdp.TransactionId(source_entity_id: UnsignedByteField, transaction_seq_num: UnsignedByteField)
Bases:
object
PDU Submodule
Configuration Submodule
- class spacepackets.cfdp.conf.PduConfig(source_entity_id: UnsignedByteField, dest_entity_id: UnsignedByteField, transaction_seq_num: UnsignedByteField, trans_mode: TransmissionMode, file_flag: LargeFileFlag = LargeFileFlag.NORMAL, crc_flag: CrcFlag = CrcFlag.NO_CRC, direction: Direction = Direction.TOWARDS_RECEIVER, seg_ctrl: SegmentationControl = SegmentationControl.NO_RECORD_BOUNDARIES_PRESERVATION)
Bases:
objectCommon configuration fields for a PDU.
- dest_entity_id: UnsignedByteField
- classmethod empty() PduConfig
Empty PDU configuration which is not valid for usage because the contained unsigned byte fields are empty (sequence number and both entity IDs)
- file_flag: LargeFileFlag = 0
- seg_ctrl: SegmentationControl = 0
- source_entity_id: UnsignedByteField
- trans_mode: TransmissionMode
- transaction_seq_num: UnsignedByteField
Length-Value (LV) Submodule
- class spacepackets.cfdp.lv.CfdpLv(value: bytes | bytearray)
Bases:
objectThis class encapsulates CFDP Length-Value (LV) fields.
- Raises:
ValueError – If value is invalid and serilization is enabled or if length of bytearray is too large.
- classmethod unpack(raw_bytes: bytes | bytearray) CfdpLv
Parses LV field at the start of the given bytearray
- Raises:
ValueError – Invalid length found