Skip to content

Commit

Permalink
add progress property
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Oct 31, 2024
1 parent 574776d commit 5807d3f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/cfdppy/handler/dest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/cfdppy/handler/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/test_dest_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions tests/test_dest_handler_acked.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_src_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 5807d3f

Please sign in to comment.