Пример #1
0
 def setUp(self):
     hdr = {
         'version': 1,
         'pdu_type': 0,
         'direction': 0,
         'transmission_mode': 1,
         'crc_flag': 0,
         'pdu_data_field_length': 25,
         'source_entity_id': 123,
         'transaction_id': 1,
         'destination_entity_id': 124
     }
     self.fixture = Header(**hdr)
Пример #2
0
    def test_header_read_write(self):
        """Write header to file, then read back to header"""
        self.fixture.is_valid()
        test_file = 'test_hdr.pdu'
        full_file_path = os.path.join(TEST_DIRECTORY, test_file)

        # write header to file
        write_outgoing_pdu(self.fixture, pdu_filename=test_file, output_directory=TEST_DIRECTORY)

        # read header from file
        pdu_object = None
        with open(full_file_path, 'rb') as pdu_file:
            bytes = pdu_file.read()
            pdu_bytes = [b for b in bytearray(bytes)]
            pdu_object = Header.to_object(pdu_bytes)

        self.assertNotEqual(pdu_object, None)
        self.assertEqual(self.fixture.version, pdu_object.version)
        self.assertEqual(self.fixture.pdu_type, pdu_object.pdu_type)
        self.assertEqual(self.fixture.direction, pdu_object.direction)
        self.assertEqual(self.fixture.crc_flag, pdu_object.crc_flag)
        self.assertEqual(self.fixture.pdu_data_field_length, pdu_object.pdu_data_field_length)
        self.assertEqual(self.fixture.source_entity_id, pdu_object.source_entity_id)
        self.assertEqual(self.fixture.transaction_id, pdu_object.transaction_id)
        self.assertEqual(self.fixture.destination_entity_id, pdu_object.destination_entity_id)
Пример #3
0
 def make_header_from_request(self, request):
     self.header = Header()
     # direction is always towards receiver because we are a sender
     self.header.direction = Header.TOWARDS_RECEIVER
     self.header.entity_ids_length = ait.config.get('dsn.cfdp.max_entity_id_length', 8) # get default entity id length, 8 bytes
     self.header.transaction_id_length = ait.config.get('dsn.cfdp.max_transaction_id_length', 8) # get default entity id length, 8 bytes
     self.header.source_entity_id = self.transaction.entity_id
     self.header.transaction_id = self.transaction.transaction_id
     self.header.destination_entity_id = request.info.get('destination_id')
     self.header.transmission_mode = request.info.get('transmission_mode')
     return self.header
Пример #4
0
    def test_header_encoding_decoding(self):
        """Convert header to bytes and then back into an object"""
        self.fixture.is_valid()
        pdu_bytes = self.fixture.to_bytes()
        pdu_object = Header.to_object(pdu_bytes)

        self.assertEqual(self.fixture.version, pdu_object.version)
        self.assertEqual(self.fixture.pdu_type, pdu_object.pdu_type)
        self.assertEqual(self.fixture.direction, pdu_object.direction)
        self.assertEqual(self.fixture.crc_flag, pdu_object.crc_flag)
        self.assertEqual(self.fixture.pdu_data_field_length, pdu_object.pdu_data_field_length)
        self.assertEqual(self.fixture.source_entity_id, pdu_object.source_entity_id)
        self.assertEqual(self.fixture.transaction_id, pdu_object.transaction_id)
        self.assertEqual(self.fixture.destination_entity_id, pdu_object.destination_entity_id)
Пример #5
0
 def setUp(self):
     hdr = {
         'version': 1,
         'pdu_type': 1,
         'direction': 0,
         'transmission_mode': 1,
         'crc_flag': 0,
         'pdu_data_field_length': 25,
         'source_entity_id': 123,
         'transaction_id': 1,
         'destination_entity_id': 124
     }
     fd = {
         'segment_offset': 0,
         'data': "Hello world this is file data."
     }
     self.fixture = FileData(**fd)
     self.fixture.header = Header(**hdr)
Пример #6
0
 def setUp(self):
     hdr = {
         'version': 1,
         'pdu_type': 0,
         'direction': 0,
         'transmission_mode': 1,
         'crc_flag': 0,
         'pdu_data_field_length': 25,
         'source_entity_id': 123,
         'transaction_id': 1,
         'destination_entity_id': 124
     }
     eof = {
         'condition_code': ConditionCode.NO_ERROR,
         'file_checksum': 12018735385,
         'file_size': 2342
     }
     self.fixture = EOF(**eof)
     self.fixture.header = Header(**hdr)
Пример #7
0
 def setUp(self):
     hdr = {
         'version': 1,
         'pdu_type': 0,
         'direction': 0,
         'transmission_mode': 1,
         'crc_flag': 0,
         'pdu_data_field_length': 25,
         'source_entity_id': 123,
         'transaction_id': 1,
         'destination_entity_id': 124
     }
     md = {
         'segmentation_control': Metadata.SEGMENTATION_CONTROL_BOUNDARIES_NOT_RESPECTED,
         'file_size': 2000,
         'source_path': '/path/to/source/file',
         'destination_path': '/path/to/destination/file'
     }
     self.fixture = Metadata(**md)
     self.fixture.header = Header(**hdr)
Пример #8
0
class HeaderTest(unittest.TestCase):

    def setUp(self):
        hdr = {
            'version': 1,
            'pdu_type': 0,
            'direction': 0,
            'transmission_mode': 1,
            'crc_flag': 0,
            'pdu_data_field_length': 25,
            'source_entity_id': 123,
            'transaction_id': 1,
            'destination_entity_id': 124
        }
        self.fixture = Header(**hdr)

    def tearDown(self):
        self.fixture = None
        for f in glob.glob(os.path.join(TEST_DIRECTORY, '*')):
            os.remove(f)

    def test_header_encoding_decoding(self):
        """Convert header to bytes and then back into an object"""
        self.fixture.is_valid()
        pdu_bytes = self.fixture.to_bytes()
        pdu_object = Header.to_object(pdu_bytes)

        self.assertEqual(self.fixture.version, pdu_object.version)
        self.assertEqual(self.fixture.pdu_type, pdu_object.pdu_type)
        self.assertEqual(self.fixture.direction, pdu_object.direction)
        self.assertEqual(self.fixture.crc_flag, pdu_object.crc_flag)
        self.assertEqual(self.fixture.pdu_data_field_length, pdu_object.pdu_data_field_length)
        self.assertEqual(self.fixture.source_entity_id, pdu_object.source_entity_id)
        self.assertEqual(self.fixture.transaction_id, pdu_object.transaction_id)
        self.assertEqual(self.fixture.destination_entity_id, pdu_object.destination_entity_id)

    def test_header_read_write(self):
        """Write header to file, then read back to header"""
        self.fixture.is_valid()
        test_file = 'test_hdr.pdu'
        full_file_path = os.path.join(TEST_DIRECTORY, test_file)

        # write header to file
        write_outgoing_pdu(self.fixture, pdu_filename=test_file, output_directory=TEST_DIRECTORY)

        # read header from file
        pdu_object = None
        with open(full_file_path, 'rb') as pdu_file:
            bytes = pdu_file.read()
            pdu_bytes = [b for b in bytearray(bytes)]
            pdu_object = Header.to_object(pdu_bytes)

        self.assertNotEqual(pdu_object, None)
        self.assertEqual(self.fixture.version, pdu_object.version)
        self.assertEqual(self.fixture.pdu_type, pdu_object.pdu_type)
        self.assertEqual(self.fixture.direction, pdu_object.direction)
        self.assertEqual(self.fixture.crc_flag, pdu_object.crc_flag)
        self.assertEqual(self.fixture.pdu_data_field_length, pdu_object.pdu_data_field_length)
        self.assertEqual(self.fixture.source_entity_id, pdu_object.source_entity_id)
        self.assertEqual(self.fixture.transaction_id, pdu_object.transaction_id)
        self.assertEqual(self.fixture.destination_entity_id, pdu_object.destination_entity_id)