diff --git a/CHANGELOG.md b/CHANGELOG.md index b1f6603..2f1d750 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). # [unreleased] +## Added + +- `progress` property for both source and destination handler to track the progress of a + transaction + # [v0.3.0] 2024-10-15 ## Changed diff --git a/src/cfdppy/handler/dest.py b/src/cfdppy/handler/dest.py index c60a6ae..933e700 100644 --- a/src/cfdppy/handler/dest.py +++ b/src/cfdppy/handler/dest.py @@ -344,6 +344,10 @@ def transmission_mode(self) -> Optional[TransmissionMode]: return None return self._params.pdu_conf.trans_mode + @property + def progress(self) -> int: + return self._params.fp.progress + @property def state(self) -> CfdpState: return self.states.state @@ -437,7 +441,6 @@ def _check_inserted_packet(self, packet: GenericPduPacket): packet.pdu_type == PduType.FILE_DATA or packet.directive_type != DirectiveType.METADATA_PDU # type: ignore ): - print(packet) self._handle_first_packet_not_metadata_pdu(packet) if packet.pdu_type == PduType.FILE_DIRECTIVE and ( packet.directive_type # type: ignore diff --git a/src/cfdppy/handler/source.py b/src/cfdppy/handler/source.py index 4a966c2..13d0408 100644 --- a/src/cfdppy/handler/source.py +++ b/src/cfdppy/handler/source.py @@ -287,6 +287,10 @@ def step(self) -> TransactionStep: def packets_ready(self) -> bool: return self.states.packets_ready + @property + def progress(self) -> int: + return self._params.fp.progress + @property def num_packets_ready(self) -> int: return self.states.num_packets_ready diff --git a/tests/test_dest_handler.py b/tests/test_dest_handler.py index 88e908a..3c927d9 100644 --- a/tests/test_dest_handler.py +++ b/tests/test_dest_handler.py @@ -203,10 +203,15 @@ def _insert_file_segment( expected_packets: int = 0, expected_step: TransactionStep = TransactionStep.RECEIVING_FILE_DATA, check_indication: bool = True, + expected_progress: Optional[int] = None, ) -> FsmResult: fd_params = FileDataParams(file_data=segment, offset=offset) file_data_pdu = FileDataPdu(params=fd_params, pdu_conf=self.src_pdu_conf) fsm_res = self.dest_handler.state_machine(file_data_pdu) + if expected_progress is None: + self.assertEqual(self.dest_handler.progress, offset + len(segment)) + else: + self.assertEqual(self.dest_handler.progress, expected_progress) if ( self.indication_cfg.file_segment_recvd_indication_required and check_indication diff --git a/tests/test_dest_handler_acked.py b/tests/test_dest_handler_acked.py index efb3e26..0899306 100644 --- a/tests/test_dest_handler_acked.py +++ b/tests/test_dest_handler_acked.py @@ -138,7 +138,7 @@ def test_immediate_missing_file_seg_handling_0(self): self._insert_file_segment(file_content[6:], 6, 1) self._generic_verify_missing_segment_requested(0, len(file_content), [(3, 6)]) # Insert the missing file content. - self._insert_file_segment(file_content[3:6], 3) + self._insert_file_segment(file_content[3:6], 3, expected_progress=12) # All lost segments were delivered, regular transfer finish. fsm_res = self._generic_insert_eof_pdu(len(file_content), crc32) self._generic_eof_recv_indication_check(fsm_res) @@ -162,7 +162,7 @@ def test_immediate_missing_file_seg_handling_1(self): # Insert the last file segment. self._insert_file_segment(file_content[6:], 6) # Now insert the missing segment. - self._insert_file_segment(file_content[2:4], 2) + self._insert_file_segment(file_content[2:4], 2, expected_progress=12) # All lost segments were delivered, regular transfer finish. fsm_res = self._generic_insert_eof_pdu(len(file_content), crc32) self._generic_eof_recv_indication_check(fsm_res) @@ -189,8 +189,8 @@ def test_immediate_multi_missing_segment_handling(self): self._generic_verify_missing_segment_requested(0, len(file_content), [(6, 8)]) # Supply the 2 missing file segments. - self._insert_file_segment(file_content[2:4], 2) - self._insert_file_segment(file_content[6:8], 6) + self._insert_file_segment(file_content[2:4], 2, expected_progress=12) + self._insert_file_segment(file_content[6:8], 6, expected_progress=12) # All lost segments were delivered, regular transfer finish. fsm_res = self._generic_insert_eof_pdu(len(file_content), crc32) self._generic_eof_recv_indication_check(fsm_res) @@ -230,6 +230,7 @@ def test_immediate_missing_segment_also_rerequested_after_eof(self): 2, 1, expected_step=TransactionStep.WAITING_FOR_FINISHED_ACK, + expected_progress=12, ) finished_pdu = self._generic_no_error_finished_pdu_check_acked(fsm_res) self._generic_verify_transfer_completion(fsm_res, file_content) @@ -271,12 +272,14 @@ def test_multi_segment_missing_deferred_handling(self): 2, expected_packets=0, expected_step=TransactionStep.WAITING_FOR_MISSING_DATA, + expected_progress=12, ) fsm_res = self._insert_file_segment( file_content[6:8], 6, expected_packets=1, expected_step=TransactionStep.WAITING_FOR_FINISHED_ACK, + expected_progress=12, ) # Done. finished_pdu = self._generic_no_error_finished_pdu_check_acked(fsm_res) @@ -410,6 +413,7 @@ def test_deferred_lost_segment_handling_after_timeout_activity_reset(self): 2, expected_packets=0, expected_step=TransactionStep.WAITING_FOR_MISSING_DATA, + expected_progress=12, ) self.dest_handler.state_machine() # Now that we inserted a packet, the NAK activity counter should be reset. @@ -429,6 +433,7 @@ def test_deferred_lost_segment_handling_after_timeout_activity_reset(self): 6, expected_packets=1, expected_step=TransactionStep.WAITING_FOR_FINISHED_ACK, + expected_progress=12, ) finished_pdu = self._generic_no_error_finished_pdu_check_acked(fsm_res) self._generic_verify_transfer_completion(fsm_res, file_content) diff --git a/tests/test_src_handler.py b/tests/test_src_handler.py index 13d5341..17ce546 100644 --- a/tests/test_src_handler.py +++ b/tests/test_src_handler.py @@ -278,6 +278,9 @@ def _generic_file_segment_handling( self.assertEqual(fd_pdu.offset, expected_offset) self.assertEqual(fd_pdu.transaction_seq_num.value, self.expected_seq_num) self.assertEqual(fd_pdu.transmission_mode, self.expected_mode) + self.assertEqual( + self.source_handler.progress, fd_pdu.offset + len(fd_pdu.file_data) + ) return fd_pdu def _check_fsm_and_contained_file_data(