Skip to content

Commit

Permalink
unit test PDU_DATA_LENGTH
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmelt committed Nov 22, 2023
1 parent 9de2549 commit c6ea835
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 16 deletions.
4 changes: 2 additions & 2 deletions microservices/CFDP/lib/cfdp_pdu/cfdp_pdu_ack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def self.build_ack_pdu(
transaction_status:)

pdu = build_initial_pdu(type: "FILE_DIRECTIVE", destination_entity: destination_entity, transmission_mode: transmission_mode, file_size: 0, segmentation_control: segmentation_control)
pdu_header_part_1_length = pdu.length # Measured here before writing variable data
pdu_header_part_1_length -= CRC_BYTE_SIZE if destination_entity['crcs_required']
pdu_header_part_1_length = pdu.length # Measured here before writing variable data - Includes CRC if present
pdu_header_part_1_length -= CRC_BYTE_SIZE if destination_entity['crcs_required'] # PDU_DATA_LENGTH field should contain CRC length
pdu_header = pdu.build_variable_header(source_entity_id: source_entity['id'], transaction_seq_num: transaction_seq_num, destination_entity_id: destination_entity['id'], directive_code: "ACK")
pdu_header_part_2_length = pdu_header.length - DIRECTIVE_CODE_BYTE_SIZE # Minus 1 = Directive code is part of data per 5.2.1.1
if ack_directive_code == "FINISHED" or ack_directive_code == 5
Expand Down
4 changes: 2 additions & 2 deletions microservices/CFDP/lib/cfdp_pdu/cfdp_pdu_eof.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def self.build_eof_pdu(
canceling_entity_id: nil)

pdu = build_initial_pdu(type: "FILE_DIRECTIVE", destination_entity: destination_entity, transmission_mode: transmission_mode, file_size: file_size, segmentation_control: segmentation_control)
pdu_header_part_1_length = pdu.length # Measured here before writing variable data
pdu_header_part_1_length -= CRC_BYTE_SIZE if destination_entity['crcs_required']
pdu_header_part_1_length = pdu.length # Measured here before writing variable data - Includes CRC if present
pdu_header_part_1_length -= CRC_BYTE_SIZE if destination_entity['crcs_required'] # PDU_DATA_LENGTH field should contain CRC length
pdu_header = pdu.build_variable_header(source_entity_id: source_entity['id'], transaction_seq_num: transaction_seq_num, destination_entity_id: destination_entity['id'], directive_code: "EOF")
pdu_header_part_2_length = pdu_header.length - DIRECTIVE_CODE_BYTE_SIZE # Minus 1 = Directive code is part of data per 5.2.1.1
pdu_contents = pdu.build_eof_pdu_contents(condition_code: condition_code, file_checksum: file_checksum, file_size: file_size, canceling_entity_id: canceling_entity_id)
Expand Down
4 changes: 2 additions & 2 deletions microservices/CFDP/lib/cfdp_pdu/cfdp_pdu_file_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def self.build_file_data_pdu(
segment_metadata: nil)

pdu = build_initial_pdu(type: "FILE_DATA", destination_entity: destination_entity, file_size: file_size, segmentation_control: segmentation_control, transmission_mode: transmission_mode)
pdu_header_part_1_length = pdu.length # Measured here before writing variable data
pdu_header_part_1_length -= CRC_BYTE_SIZE if destination_entity['crcs_required']
pdu_header_part_1_length = pdu.length # Measured here before writing variable data - Includes CRC if present
pdu_header_part_1_length -= CRC_BYTE_SIZE if destination_entity['crcs_required'] # PDU_DATA_LENGTH field should contain CRC length
pdu_header = pdu.build_variable_header(source_entity_id: source_entity['id'], transaction_seq_num: transaction_seq_num, destination_entity_id: destination_entity['id'])
pdu_header_part_2_length = pdu_header.length
pdu_contents = pdu.build_file_data_pdu_contents(offset: offset, file_data: file_data, record_continuation_state: record_continuation_state, segment_metadata: segment_metadata)
Expand Down
4 changes: 2 additions & 2 deletions microservices/CFDP/lib/cfdp_pdu/cfdp_pdu_finished.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def self.build_finished_pdu(

pdu = build_initial_pdu(type: "FILE_DIRECTIVE", destination_entity: destination_entity, transmission_mode: transmission_mode, file_size: 0, segmentation_control: segmentation_control)
pdu.write("DIRECTION", "TOWARD_FILE_SENDER")
pdu_header_part_1_length = pdu.length # Measured here before writing variable data
pdu_header_part_1_length -= CRC_BYTE_SIZE if destination_entity['crcs_required']
pdu_header_part_1_length = pdu.length # Measured here before writing variable data - Includes CRC if present
pdu_header_part_1_length -= CRC_BYTE_SIZE if destination_entity['crcs_required'] # PDU_DATA_LENGTH field should contain CRC length
pdu_header = pdu.build_variable_header(source_entity_id: source_entity['id'], transaction_seq_num: transaction_seq_num, destination_entity_id: destination_entity['id'], directive_code: "FINISHED")
pdu_header_part_2_length = pdu_header.length - DIRECTIVE_CODE_BYTE_SIZE # Minus 1 = Directive code is part of data per 5.2.1.1
pdu_contents = pdu.build_finished_pdu_contents(condition_code: condition_code, delivery_code: delivery_code, file_status: file_status, filestore_responses: filestore_responses, fault_location_entity_id: fault_location_entity_id)
Expand Down
4 changes: 2 additions & 2 deletions microservices/CFDP/lib/cfdp_pdu/cfdp_pdu_keep_alive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def self.build_keep_alive_pdu(

pdu = build_initial_pdu(type: "FILE_DIRECTIVE", destination_entity: destination_entity, transmission_mode: transmission_mode, file_size: file_size, segmentation_control: segmentation_control)
pdu.write("DIRECTION", "TOWARD_FILE_SENDER")
pdu_header_part_1_length = pdu.length # Measured here before writing variable data
pdu_header_part_1_length -= CRC_BYTE_SIZE if destination_entity['crcs_required']
pdu_header_part_1_length = pdu.length # Measured here before writing variable data - Includes CRC if present
pdu_header_part_1_length -= CRC_BYTE_SIZE if destination_entity['crcs_required'] # PDU_DATA_LENGTH field should contain CRC length
pdu_header = pdu.build_variable_header(source_entity_id: source_entity['id'], transaction_seq_num: transaction_seq_num, destination_entity_id: destination_entity['id'], directive_code: "KEEP_ALIVE")
pdu_header_part_2_length = pdu_header.length - DIRECTIVE_CODE_BYTE_SIZE # Minus 1 = Directive code is part of data per 5.2.1.1
pdu_contents = pdu.build_keep_alive_pdu_contents(progress: progress)
Expand Down
4 changes: 2 additions & 2 deletions microservices/CFDP/lib/cfdp_pdu/cfdp_pdu_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def self.build_metadata_pdu(
options: [])

pdu = build_initial_pdu(type: "FILE_DIRECTIVE", destination_entity: destination_entity, transmission_mode: transmission_mode, file_size: file_size, segmentation_control: segmentation_control)
pdu_header_part_1_length = pdu.length # Measured here before writing variable data
pdu_header_part_1_length -= CRC_BYTE_SIZE if destination_entity['crcs_required']
pdu_header_part_1_length = pdu.length # Measured here before writing variable data - Includes CRC if present
pdu_header_part_1_length -= CRC_BYTE_SIZE if destination_entity['crcs_required'] # PDU_DATA_LENGTH field should contain CRC length
pdu_header = pdu.build_variable_header(source_entity_id: source_entity['id'], transaction_seq_num: transaction_seq_num, destination_entity_id: destination_entity['id'], directive_code: "METADATA")
pdu_header_part_2_length = pdu_header.length - DIRECTIVE_CODE_BYTE_SIZE # Minus 1 = Directive code is part of data per 5.2.1.1
if checksum_type_implemented(destination_entity['default_checksum_type'])
Expand Down
4 changes: 2 additions & 2 deletions microservices/CFDP/lib/cfdp_pdu/cfdp_pdu_nak.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def self.build_nak_pdu(

pdu = build_initial_pdu(type: "FILE_DIRECTIVE", destination_entity: destination_entity, transmission_mode: transmission_mode, file_size: file_size, segmentation_control: segmentation_control)
pdu.write("DIRECTION", "TOWARD_FILE_SENDER")
pdu_header_part_1_length = pdu.length # Measured here before writing variable data
pdu_header_part_1_length -= CRC_BYTE_SIZE if destination_entity['crcs_required']
pdu_header_part_1_length = pdu.length # Measured here before writing variable data - Includes CRC if present
pdu_header_part_1_length -= CRC_BYTE_SIZE if destination_entity['crcs_required'] # PDU_DATA_LENGTH field should contain CRC length
pdu_header = pdu.build_variable_header(source_entity_id: source_entity['id'], transaction_seq_num: transaction_seq_num, destination_entity_id: destination_entity['id'], directive_code: "NAK")
pdu_header_part_2_length = pdu_header.length - DIRECTIVE_CODE_BYTE_SIZE # Minus 1 = Directive code is part of data per 5.2.1.1
pdu_contents = pdu.build_nak_pdu_contents(start_of_scope: start_of_scope, end_of_scope: end_of_scope, segment_requests: segment_requests)
Expand Down
4 changes: 2 additions & 2 deletions microservices/CFDP/lib/cfdp_pdu/cfdp_pdu_prompt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def self.build_prompt_pdu(
response_required:)

pdu = build_initial_pdu(type: "FILE_DIRECTIVE", destination_entity: destination_entity, transmission_mode: transmission_mode, file_size: 0, segmentation_control: segmentation_control)
pdu_header_part_1_length = pdu.length # Measured here before writing variable data
pdu_header_part_1_length -= CRC_BYTE_SIZE if destination_entity['crcs_required']
pdu_header_part_1_length = pdu.length # Measured here before writing variable data - Includes CRC if present
pdu_header_part_1_length -= CRC_BYTE_SIZE if destination_entity['crcs_required'] # PDU_DATA_LENGTH field should contain CRC length
pdu_header = pdu.build_variable_header(source_entity_id: source_entity['id'], transaction_seq_num: transaction_seq_num, destination_entity_id: destination_entity['id'], directive_code: "PROMPT")
pdu_header_part_2_length = pdu_header.length - DIRECTIVE_CODE_BYTE_SIZE # Minus 1 = Directive code is part of data per 5.2.1.1
pdu_contents = pdu.build_prompt_pdu_contents(response_required: response_required)
Expand Down
1 change: 1 addition & 0 deletions microservices/CFDP/spec/models/cfdp_pdu_ack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

# By default the first 7 bytes are the header
# This assumes 1 byte per entity ID and sequence number
expect(buffer[1..2].unpack('n')[0]).to eql 5 # PDU_DATA_LENGTH - Directive Code plus Ack Data plus CRC

# Directive Code
expect(buffer[7].unpack('C')[0]).to eql 6 # ACK per Table 5-4
Expand Down
1 change: 1 addition & 0 deletions microservices/CFDP/spec/models/cfdp_pdu_eof_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

# By default the first 7 bytes are the header
# This assumes 1 byte per entity ID and sequence number
expect(buffer[1..2].unpack('n')[0]).to eql 12 # PDU_DATA_LENGTH - Directive Code plus Data plus CRC

# Directive Code
expect(buffer[7].unpack('C')[0]).to eql 4 # EOF per Table 5-4
Expand Down
1 change: 1 addition & 0 deletions microservices/CFDP/spec/models/cfdp_pdu_file_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

# By default the first 7 bytes are the header
# This assumes 1 byte per entity ID and sequence number
expect(buffer[1..2].unpack('n')[0]).to eql 8 # PDU_DATA_LENGTH - Directive Code plus Data plus CRC

# PDU Type
expect((buffer[0].unpack('C')[0] >> 4) & 0x1).to eql 1 # File Data per Table 5-1
Expand Down
1 change: 1 addition & 0 deletions microservices/CFDP/spec/models/cfdp_pdu_finished_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

# By default the first 7 bytes are the header
# This assumes 1 byte per entity ID and sequence number
expect(buffer[1..2].unpack('n')[0]).to eql 4 # PDU_DATA_LENGTH - Directive Code plus Data plus CRC

# Directive Code
expect(buffer[7].unpack('C')[0]).to eql 5 # Finished per Table 5-4
Expand Down
1 change: 1 addition & 0 deletions microservices/CFDP/spec/models/cfdp_pdu_keep_alive_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

# By default the first 7 bytes are the header
# This assumes 1 byte per entity ID and sequence number
expect(buffer[1..2].unpack('n')[0]).to eql 7 # PDU_DATA_LENGTH - Directive Code plus Data plus CRC

# Directive Code
expect(buffer[7].unpack('C')[0]).to eql 0x0C # Keep Alive per Table 5-4
Expand Down
1 change: 1 addition & 0 deletions microservices/CFDP/spec/models/cfdp_pdu_metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

# By default the first 7 bytes are the header
# This assumes 1 byte per entity ID and sequence number
expect(buffer[1..2].unpack('n')[0]).to eql 22 # PDU_DATA_LENGTH - Directive Code plus Data plus CRC

# Directive Code
expect(buffer[7].unpack('C')[0]).to eql 7 # Metadata per Table 5-4
Expand Down
1 change: 1 addition & 0 deletions microservices/CFDP/spec/models/cfdp_pdu_nak_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

# By default the first 7 bytes are the header
# This assumes 1 byte per entity ID and sequence number
expect(buffer[1..2].unpack('n')[0]).to eql 11 # PDU_DATA_LENGTH - Directive Code plus Data plus CRC

# Directive Code
expect(buffer[7].unpack('C')[0]).to eql 8 # NAK per Table 5-4
Expand Down
1 change: 1 addition & 0 deletions microservices/CFDP/spec/models/cfdp_pdu_prompt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

# By default the first 7 bytes are the header
# This assumes 1 byte per entity ID and sequence number
expect(buffer[1..2].unpack('n')[0]).to eql 4 # PDU_DATA_LENGTH - Directive Code plus Data plus CRC

# Directive Code
expect(buffer[7].unpack('C')[0]).to eql 9 # Prompt per Table 5-4
Expand Down

0 comments on commit c6ea835

Please sign in to comment.