11import struct
22import time
33
4+ import fastcrc
45from spacepackets .cfdp import (
56 NULL_CHECKSUM_U32 ,
67 ConditionCode ,
1819 FinishedPdu ,
1920 TransactionStatus ,
2021)
21- from spacepackets .crc import mkPredefinedCrcFun
2222
2323from cfdppy .defs import CfdpState
2424from cfdppy .handler .dest import FsmResult , TransactionStep
@@ -45,12 +45,12 @@ def test_acked_small_file_transfer(self):
4545 file_content = b"Hello World!"
4646 with open (self .src_file_path , "wb" ) as of :
4747 of .write (file_content )
48- crc32_func = mkPredefinedCrcFun ( " crc32" )
49- crc32 = struct .pack ("!I" , crc32_func ( file_content ) )
48+ crc32 = fastcrc . crc32 . iso_hdlc ( file_content )
49+ crc32_bytes = struct .pack ("!I" , crc32 )
5050 # Basic acknowledged empty file transfer.
5151 self ._generic_regular_transfer_init (len (file_content ))
5252 self ._insert_file_segment (file_content , 0 )
53- fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32 )
53+ fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32_bytes )
5454 self ._generic_eof_recv_indication_check (fsm_res )
5555 self ._generic_verify_eof_ack_packet (fsm_res , TransactionStep .WAITING_FOR_FINISHED_ACK )
5656 finished_pdu = self ._generic_no_error_finished_pdu_check_acked (fsm_res )
@@ -99,11 +99,11 @@ def test_deferred_missing_file_segment_handling(self):
9999 file_content = b"Hello World!"
100100 with open (self .src_file_path , "wb" ) as of :
101101 of .write (file_content )
102- crc32_func = mkPredefinedCrcFun ( " crc32" )
103- crc32 = struct .pack ("!I" , crc32_func ( file_content ) )
102+ crc32 = fastcrc . crc32 . iso_hdlc ( file_content )
103+ crc32_bytes = struct .pack ("!I" , crc32 )
104104 self ._generic_regular_transfer_init (len (file_content ))
105105 self ._insert_file_segment (file_content [0 :5 ], 0 )
106- fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32 )
106+ fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32_bytes )
107107 self ._generic_eof_recv_indication_check (fsm_res )
108108 self ._generic_verify_eof_ack_packet (fsm_res , TransactionStep .WAITING_FOR_MISSING_DATA )
109109 self ._state_checker (fsm_res , 1 , CfdpState .BUSY , TransactionStep .WAITING_FOR_MISSING_DATA )
@@ -126,8 +126,8 @@ def test_immediate_missing_file_seg_handling_0(self):
126126 file_content = b"Hello World!"
127127 with open (self .src_file_path , "wb" ) as of :
128128 of .write (file_content )
129- crc32_func = mkPredefinedCrcFun ( " crc32" )
130- crc32 = struct .pack ("!I" , crc32_func ( file_content ) )
129+ crc32 = fastcrc . crc32 . iso_hdlc ( file_content )
130+ crc32_bytes = struct .pack ("!I" , crc32 )
131131 self ._generic_regular_transfer_init (len (file_content ))
132132 # A middle segment is missing now, with the expected lost segment tuple to be (3, 6). The
133133 # lost segment is immediately supplied.
@@ -137,7 +137,7 @@ def test_immediate_missing_file_seg_handling_0(self):
137137 # Insert the missing file content.
138138 self ._insert_file_segment (file_content [3 :6 ], 3 , expected_progress = 12 )
139139 # All lost segments were delivered, regular transfer finish.
140- fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32 )
140+ fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32_bytes )
141141 self ._generic_eof_recv_indication_check (fsm_res )
142142 self ._generic_verify_eof_ack_packet (fsm_res , TransactionStep .WAITING_FOR_FINISHED_ACK )
143143 finished_pdu = self ._generic_no_error_finished_pdu_check_acked (fsm_res )
@@ -148,8 +148,8 @@ def test_immediate_missing_file_seg_handling_1(self):
148148 file_content = b"Hello World!"
149149 with open (self .src_file_path , "wb" ) as of :
150150 of .write (file_content )
151- crc32_func = mkPredefinedCrcFun ( " crc32" )
152- crc32 = struct .pack ("!I" , crc32_func ( file_content ) )
151+ crc32 = fastcrc . crc32 . iso_hdlc ( file_content )
152+ crc32_bytes = struct .pack ("!I" , crc32 )
153153 self ._generic_regular_transfer_init (len (file_content ))
154154 # Simulate the second segment being lost, with more than one segment following after that.
155155 self ._insert_file_segment (file_content [0 :2 ], 0 )
@@ -160,7 +160,7 @@ def test_immediate_missing_file_seg_handling_1(self):
160160 # Now insert the missing segment.
161161 self ._insert_file_segment (file_content [2 :4 ], 2 , expected_progress = 12 )
162162 # All lost segments were delivered, regular transfer finish.
163- fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32 )
163+ fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32_bytes )
164164 self ._generic_eof_recv_indication_check (fsm_res )
165165 self ._generic_verify_eof_ack_packet (fsm_res , TransactionStep .WAITING_FOR_FINISHED_ACK )
166166 finished_pdu = self ._generic_no_error_finished_pdu_check_acked (fsm_res )
@@ -171,8 +171,8 @@ def test_immediate_multi_missing_segment_handling(self):
171171 file_content = b"Hello World!"
172172 with open (self .src_file_path , "wb" ) as of :
173173 of .write (file_content )
174- crc32_func = mkPredefinedCrcFun ( " crc32" )
175- crc32 = struct .pack ("!I" , crc32_func ( file_content ) )
174+ crc32 = fastcrc . crc32 . iso_hdlc ( file_content )
175+ crc32_bytes = struct .pack ("!I" , crc32 )
176176 self ._generic_regular_transfer_init (len (file_content ))
177177 self ._insert_file_segment (file_content [0 :2 ], 0 )
178178 self ._insert_file_segment (file_content [4 :6 ], 4 , 1 )
@@ -187,7 +187,7 @@ def test_immediate_multi_missing_segment_handling(self):
187187 self ._insert_file_segment (file_content [2 :4 ], 2 , expected_progress = 12 )
188188 self ._insert_file_segment (file_content [6 :8 ], 6 , expected_progress = 12 )
189189 # All lost segments were delivered, regular transfer finish.
190- fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32 )
190+ fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32_bytes )
191191 self ._generic_eof_recv_indication_check (fsm_res )
192192 self ._generic_verify_eof_ack_packet (fsm_res , TransactionStep .WAITING_FOR_FINISHED_ACK )
193193 finished_pdu = self ._generic_no_error_finished_pdu_check_acked (fsm_res )
@@ -198,8 +198,8 @@ def test_immediate_missing_segment_also_rerequested_after_eof(self):
198198 file_content = b"Hello World!"
199199 with open (self .src_file_path , "wb" ) as of :
200200 of .write (file_content )
201- crc32_func = mkPredefinedCrcFun ( " crc32" )
202- crc32 = struct .pack ("!I" , crc32_func ( file_content ) )
201+ crc32 = fastcrc . crc32 . iso_hdlc ( file_content )
202+ crc32_bytes = struct .pack ("!I" , crc32 )
203203 self ._generic_regular_transfer_init (len (file_content ))
204204 # Missing middle segment
205205 self ._insert_file_segment (file_content [0 :2 ], 0 )
@@ -208,7 +208,7 @@ def test_immediate_missing_segment_also_rerequested_after_eof(self):
208208 self ._generic_verify_missing_segment_requested (0 , len (file_content ), [(2 , 6 )])
209209
210210 # All lost segments were delivered, regular transfer finish.
211- fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32 )
211+ fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32_bytes )
212212 self ._generic_eof_recv_indication_check (fsm_res )
213213 self ._generic_verify_eof_ack_packet (fsm_res , TransactionStep .WAITING_FOR_MISSING_DATA )
214214 self ._state_checker (fsm_res , 1 , CfdpState .BUSY , TransactionStep .WAITING_FOR_MISSING_DATA )
@@ -230,8 +230,8 @@ def test_multi_segment_missing_deferred_handling(self):
230230 file_content = b"Hello World!"
231231 with open (self .src_file_path , "wb" ) as of :
232232 of .write (file_content )
233- crc32_func = mkPredefinedCrcFun ( " crc32" )
234- crc32 = struct .pack ("!I" , crc32_func ( file_content ) )
233+ crc32 = fastcrc . crc32 . iso_hdlc ( file_content )
234+ crc32_bytes = struct .pack ("!I" , crc32 )
235235 self ._generic_regular_transfer_init (len (file_content ))
236236 self ._insert_file_segment (file_content [0 :2 ], 0 )
237237 self ._insert_file_segment (file_content [4 :6 ], 4 , 1 )
@@ -242,7 +242,7 @@ def test_multi_segment_missing_deferred_handling(self):
242242 self ._insert_file_segment (file_content [8 :], 8 , 1 )
243243 self ._generic_verify_missing_segment_requested (0 , len (file_content ), [(6 , 8 )])
244244
245- fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32 )
245+ fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32_bytes )
246246 self ._generic_eof_recv_indication_check (fsm_res )
247247 self ._generic_verify_eof_ack_packet (fsm_res , TransactionStep .WAITING_FOR_MISSING_DATA )
248248 self ._state_checker (fsm_res , 1 , CfdpState .BUSY , TransactionStep .WAITING_FOR_MISSING_DATA )
@@ -274,8 +274,8 @@ def test_missing_metadata_pdu(self):
274274 file_content = b"Hello World!"
275275 with open (self .src_file_path , "wb" ) as of :
276276 of .write (file_content )
277- crc32_func = mkPredefinedCrcFun ( " crc32" )
278- crc32 = struct .pack ("!I" , crc32_func ( file_content ) )
277+ crc32 = fastcrc . crc32 . iso_hdlc ( file_content )
278+ crc32_bytes = struct .pack ("!I" , crc32 )
279279 self ._insert_file_segment (
280280 file_content [0 :2 ],
281281 0 ,
@@ -308,7 +308,7 @@ def test_missing_metadata_pdu(self):
308308 2 ,
309309 )
310310 # All lost segments were delivered, regular transfer finish.
311- fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32 )
311+ fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32_bytes )
312312 self ._generic_eof_recv_indication_check (fsm_res )
313313 self ._generic_verify_eof_ack_packet (fsm_res , TransactionStep .WAITING_FOR_FINISHED_ACK )
314314 finished_pdu = self ._generic_no_error_finished_pdu_check_acked (fsm_res )
@@ -337,8 +337,8 @@ def test_metadata_eof_only_missing_metadata(self):
337337 def _generic_deferred_lost_segment_handling_with_timeout (self , file_content : bytes ):
338338 with open (self .src_file_path , "wb" ) as of :
339339 of .write (file_content )
340- crc32_func = mkPredefinedCrcFun ( " crc32" )
341- crc32 = struct .pack ("!I" , crc32_func ( file_content ) )
340+ crc32 = fastcrc . crc32 . iso_hdlc ( file_content )
341+ crc32_bytes = struct .pack ("!I" , crc32 )
342342 self ._generic_regular_transfer_init (len (file_content ))
343343 self ._insert_file_segment (file_content [0 :2 ], 0 )
344344 self ._insert_file_segment (file_content [4 :6 ], 4 , 1 )
@@ -350,7 +350,7 @@ def _generic_deferred_lost_segment_handling_with_timeout(self, file_content: byt
350350 self ._generic_verify_missing_segment_requested (0 , len (file_content ), [(6 , 8 )])
351351
352352 # This should trigger deferred EOF handling.
353- fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32 )
353+ fsm_res = self ._generic_insert_eof_pdu (len (file_content ), crc32_bytes )
354354 self ._generic_eof_recv_indication_check (fsm_res )
355355 self ._generic_verify_eof_ack_packet (fsm_res , TransactionStep .WAITING_FOR_MISSING_DATA )
356356 self ._state_checker (fsm_res , 1 , CfdpState .BUSY , TransactionStep .WAITING_FOR_MISSING_DATA )
0 commit comments