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: object

This 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 from_path(path: Path) CfdpLv
classmethod from_str(string: str) CfdpLv
pack() bytearray
property packet_len: int

Returns length of full LV packet

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: AbstractTlvBase

Encapsulates 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
pack() bytearray
property packet_len: int
property tlv_type: TlvType
classmethod unpack(data: bytes | bytearray) CfdpTlv

Parses LV field at the start of the given bytearray

Parameters:

data

Raises:
Returns:

property value: bytes
class spacepackets.cfdp.ChecksumType(value)

Bases: IntEnum

An enumeration.

CRC_32 = 3
CRC_32C = 2
CRC_32_PROXIMITY_1 = 1
MODULAR = 0
NULL_CHECKSUM = 15
class spacepackets.cfdp.ConditionCode(value)

Bases: IntEnum

An 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.CrcFlag(value)

Bases: IntEnum

An enumeration.

NO_CRC = 0
WITH_CRC = 1
class spacepackets.cfdp.DeliveryCode(value)

Bases: IntEnum

An enumeration.

DATA_COMPLETE = 0
DATA_INCOMPLETE = 1
class spacepackets.cfdp.Direction(value)

Bases: IntEnum

This is used for PDU forwarding

TOWARDS_RECEIVER = 0
TOWARDS_SENDER = 1
class spacepackets.cfdp.DirectiveType(value)

Bases: IntEnum

An 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: AbstractTlvBase

This 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
pack() bytearray
property packet_len: int
property tlv_type: TlvType
classmethod unpack(data: bytes | bytearray) EntityIdTlv
property value: bytes
class spacepackets.cfdp.FaultHandlerCode(value)

Bases: IntEnum

An 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
pack() bytearray
property packet_len: int
property tlv_type: TlvType
classmethod unpack(data: bytes) FaultHandlerOverrideTlv
property value: bytes
class spacepackets.cfdp.FileStatus(value)

Bases: IntEnum

An 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
generate_tlv() None
pack() bytearray
property packet_len: int
property tlv_type: TlvType
classmethod unpack(data: bytes) FileStoreRequestTlv
property value: bytes
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
generate_tlv() None
pack() bytearray
property packet_len: int
property tlv_type: TlvType
classmethod unpack(data: bytes | bytearray) FileStoreResponseTlv
property value: bytes
class spacepackets.cfdp.FilestoreActionCode(value)

Bases: IntEnum

All 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: IntEnum

File 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 FinishedPdu PDU.

class spacepackets.cfdp.FlowLabelTlv(flow_label: bytes)

Bases: AbstractTlvBase

TLV_TYPE = 5
classmethod from_tlv(cfdp_tlv: CfdpTlv) FlowLabelTlv
pack() bytearray
property packet_len: int
property tlv_type: TlvType
classmethod unpack(data: bytes) FlowLabelTlv
property value: bytes
exception spacepackets.cfdp.InvalidCrcError(crc16: int, message: str | None = None)

Bases: Exception

class spacepackets.cfdp.LargeFileFlag(value)

Bases: IntEnum

An enumeration.

LARGE = 1
NORMAL = 0
class spacepackets.cfdp.MessageToUserTlv(msg: bytes)

Bases: AbstractTlvBase

Message 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
is_reserved_cfdp_message() bool
pack() bytearray
property packet_len: int
property tlv_type: TlvType
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 ReservedCfdpMessage API.

classmethod unpack(data: bytes | bytearray) MessageToUserTlv
property value: bytes
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: object

Common configuration fields for a PDU.

crc_flag: CrcFlag = 0
classmethod default() PduConfig

Valid PDU configuration

dest_entity_id: UnsignedByteField
direction: Direction = 0
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
header_len() int
seg_ctrl: SegmentationControl = 0
source_entity_id: UnsignedByteField
trans_mode: TransmissionMode
transaction_seq_num: UnsignedByteField
class spacepackets.cfdp.PduFactory

Bases: object

Helper class to generate PDUs and retrieve PDU information from a raw bytestream

static from_raw(data: bytes | bytearray) AbstractFileDirectiveBase | AbstractPduBase | None
static from_raw_to_holder(data: bytes | bytearray) PduHolder
static is_file_directive(data: bytes | bytearray) bool
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.

static pdu_type(data: bytes | bytearray) PduType
class spacepackets.cfdp.PduHolder(pdu: AbstractFileDirectiveBase | AbstractPduBase | None)

Bases: object

Helper 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 is_file_directive: bool
pack() bytearray
property packet_len: int
property pdu_directive_type: DirectiveType | None

If the contained type is not a PDU file directive, returns None. Otherwise, returns the directive type

property pdu_type: PduType
to_ack_pdu() AckPdu
to_eof_pdu() EofPdu
to_file_data_pdu() FileDataPdu
to_finished_pdu() FinishedPdu
to_keep_alive_pdu() KeepAlivePdu
to_metadata_pdu() MetadataPdu
to_nak_pdu() NakPdu
to_prompt_pdu() PromptPdu
class spacepackets.cfdp.PduType(value)

Bases: IntEnum

An enumeration.

FILE_DATA = 1
FILE_DIRECTIVE = 0
class spacepackets.cfdp.SegmentMetadataFlag(value)

Bases: IntEnum

Aways 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: IntEnum

Always 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

property tlv_type: None | TlvType
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: IntEnum

All 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

class spacepackets.cfdp.TransmissionMode(value)

Bases: IntEnum

An enumeration.

ACKNOWLEDGED = 0
UNACKNOWLEDGED = 1

PDU Submodule

CFDP PDU Subpackage

Configuration Submodule

class spacepackets.cfdp.conf.CfdpDict

Bases: TypedDict

source_dest_entity_ids: tuple[bytes, bytes]
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: object

Common configuration fields for a PDU.

crc_flag: CrcFlag = 0
classmethod default() PduConfig

Valid PDU configuration

dest_entity_id: UnsignedByteField
direction: Direction = 0
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
header_len() int
seg_ctrl: SegmentationControl = 0
source_entity_id: UnsignedByteField
trans_mode: TransmissionMode
transaction_seq_num: UnsignedByteField
spacepackets.cfdp.conf.get_entity_ids() tuple[bytes, bytes]

Return a tuple where the first entry is the source entity ID

spacepackets.cfdp.conf.set_entity_ids(source_entity_id: bytes, dest_entity_id: bytes) None

Length-Value (LV) Submodule

class spacepackets.cfdp.lv.CfdpLv(value: bytes | bytearray)

Bases: object

This 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 from_path(path: Path) CfdpLv
classmethod from_str(string: str) CfdpLv
pack() bytearray
property packet_len: int

Returns length of full LV packet

classmethod unpack(raw_bytes: bytes | bytearray) CfdpLv

Parses LV field at the start of the given bytearray

Raises:

ValueError – Invalid length found