Ejemplo n.º 1
0
    def test_to_primitive(self):
        """ Check converting PDU to primitive """
        pdu = A_ASSOCIATE_RJ()
        pdu.decode(a_associate_rj)

        primitive = pdu.to_primitive()

        assert primitive.result == 1
        assert primitive.result_source == 1
        assert primitive.diagnostic == 1
        assert isinstance(primitive.result, int)
        assert isinstance(primitive.result_source, int)
        assert isinstance(primitive.diagnostic, int)

        # Not used by A-ASSOCIATE-RJ or fixed value
        assert primitive.mode == "normal"
        assert primitive.application_context_name is None
        assert primitive.calling_ae_title is None
        assert primitive.called_ae_title is None
        assert primitive.responding_ae_title is None
        assert primitive.user_information == []
        assert primitive.calling_presentation_address is None
        assert primitive.called_presentation_address is None
        assert primitive.responding_presentation_address == (
            primitive.called_presentation_address)
        assert primitive.presentation_context_definition_list == []
        assert primitive.presentation_context_definition_results_list == []
        assert primitive.presentation_requirements == "Presentation Kernel"
        assert primitive.session_requirements == ""
Ejemplo n.º 2
0
    def test_to_primitive(self):
        """ Check converting PDU to primitive """
        pdu = A_ASSOCIATE_RJ()
        pdu.Decode(a_associate_rj)

        primitive = pdu.ToParams()

        self.assertEqual(primitive.result, 1)
        self.assertEqual(primitive.result_source, 1)
        self.assertEqual(primitive.diagnostic, 1)
        self.assertTrue(isinstance(primitive.result, int))
        self.assertTrue(isinstance(primitive.result_source, int))
        self.assertTrue(isinstance(primitive.diagnostic, int))

        # Not used by A-ASSOCIATE-RJ or fixed value
        self.assertEqual(primitive.mode, "normal")
        self.assertEqual(primitive.application_context_name, None)
        self.assertEqual(primitive.calling_ae_title, None)
        self.assertEqual(primitive.called_ae_title, None)
        self.assertEqual(primitive.responding_ae_title, None)
        self.assertEqual(primitive.user_information, [])
        self.assertEqual(primitive.calling_presentation_address, None)
        self.assertEqual(primitive.called_presentation_address, None)
        self.assertEqual(primitive.responding_presentation_address,
                         primitive.called_presentation_address)
        self.assertEqual(primitive.presentation_context_definition_list, [])
        self.assertEqual(
            primitive.presentation_context_definition_results_list, [])
        self.assertEqual(primitive.presentation_requirements,
                         "Presentation Kernel")
        self.assertEqual(primitive.session_requirements, "")
Ejemplo n.º 3
0
    def test_new_encode(self):
        """ Check encoding using new generic method """
        pdu = A_ASSOCIATE_RJ()
        pdu.Decode(a_associate_rj)
        s = pdu.encode()

        self.assertEqual(s, a_associate_rj)
Ejemplo n.º 4
0
    def test_stream_encode(self):
        """ Check encoding an assoc_rj produces the correct output """
        pdu = A_ASSOCIATE_RJ()
        pdu.Decode(a_associate_rj)
        s = pdu.Encode()

        self.assertEqual(s, a_associate_rj)
Ejemplo n.º 5
0
    def test_generic_encode(self):
        """ Check using the new pdu.encode produces the correct output """
        pdu = A_ASSOCIATE_RJ()
        pdu.Decode(a_associate_rj)
        s = pdu.Encode()
        t = pdu.encode()

        self.assertEqual(s, t)
Ejemplo n.º 6
0
    def test_stream_decode_values_types(self):
        """ Check decoding the assoc_rj stream produces the correct objects """
        pdu = A_ASSOCIATE_RJ()
        pdu.Decode(a_associate_rj)

        self.assertEqual(pdu.pdu_type, 0x03)
        self.assertEqual(pdu.pdu_length, 4)
        self.assertTrue(isinstance(pdu.pdu_type, int))
        self.assertTrue(isinstance(pdu.pdu_length, int))
Ejemplo n.º 7
0
    def test_decode_properties(self):
        """ Check decoding produces the correct properties """
        pdu = A_ASSOCIATE_RJ()
        pdu.decode(a_associate_rj)

        # Check reason/source/result
        assert pdu.result_str == 'Rejected (Permanent)'
        assert pdu.reason_str == 'No reason given'
        assert pdu.source_str == 'DUL service-user'
Ejemplo n.º 8
0
    def test_decod(self):
        """ Check decoding produces the correct objects """
        pdu = A_ASSOCIATE_RJ()
        pdu.decode(a_associate_rj)

        assert pdu.pdu_type == 0x03
        assert pdu.pdu_length == 4
        assert len(pdu) == 10
        assert pdu.result == 1
        assert pdu.source == 1
        assert pdu.reason_diagnostic == 1
Ejemplo n.º 9
0
    def test_decode_properties(self):
        """ Check decoding the assoc_rj stream produces the correct properties """
        pdu = A_ASSOCIATE_RJ()
        pdu.Decode(a_associate_rj)

        # Check reason/source/result
        self.assertEqual(pdu.result, 1)
        self.assertEqual(pdu.reason_diagnostic, 1)
        self.assertEqual(pdu.source, 1)
        self.assertTrue(isinstance(pdu.result, int))
        self.assertTrue(isinstance(pdu.reason_diagnostic, int))
        self.assertTrue(isinstance(pdu.source, int))
Ejemplo n.º 10
0
    def test_from_primitive(self):
        """ Check converting PDU to primitive """
        orig_pdu = A_ASSOCIATE_RJ()
        orig_pdu.decode(a_associate_rj)

        primitive = orig_pdu.to_primitive()

        new_pdu = A_ASSOCIATE_RJ()
        new_pdu.from_primitive(primitive)

        assert new_pdu == orig_pdu
Ejemplo n.º 11
0
def AE_8(dul):
    """Association establishment action AE-8.

    On receiving association request rejection, issue A-ASSOCIATE-RJ

    State-event triggers: Sta3 + Evt8

    .. [1] DICOM Standard 2015b, PS3.8, Table 9-7, "Associate Establishment
        Related Actions"

    Parameters
    ----------
    dul : pynetdicom3.dul.DULServiceProvider
        The DICOM Upper Layer Service instance for the local AE

    Returns
    -------
    str
        Sta13, the next state of the state machine
    """
    # Send A-ASSOCIATE-RJ PDU and start ARTIM timer
    dul.pdu = A_ASSOCIATE_RJ()
    dul.pdu.FromParams(dul.primitive)

    # Callback
    dul.assoc.acse.debug_send_associate_rj(dul.pdu)

    dul.scu_socket.send(dul.pdu.Encode())

    dul.artim_timer.start()

    return 'Sta13'
Ejemplo n.º 12
0
def AE_6(dul):
    """Association establishment action AE-6.

    On receiving an A-ASSOCIATE-RQ PDU from the peer then stop the ARTIM timer
    and then either
        * issue an A-ASSOCIATE indication primitive if the -RQ is acceptable or
        * issue an A-ASSOCIATE-RJ PDU to the peer and start the ARTIM timer

    This is a lower-level DUL Service Provider initiated rejection - for example
        this could be where the protocol version is checked

    State-event triggers: Sta2 + Evt6

    .. [1] DICOM Standard 2015b, PS3.8, Table 9-7, "Associate Establishment
        Related Actions"

    Parameters
    ----------
    dul : pynetdicom3.dul.DULServiceProvider
        The DICOM Upper Layer Service instance for the local AE

    Returns
    -------
    str
        Either Sta3 or Sta13, the next state of the state machine
    """
    # Stop ARTIM timer
    dul.artim_timer.stop()

    # If A-ASSOCIATE-RQ not acceptable by service dul provider
    #   Then set reason and send -RJ PDU back to peer
    if dul.pdu.protocol_version != 0x0001:
        LOGGER.error("Receiving Association failed: Unsupported peer protocol "
                     "version '0x%04x' (0x0001 expected)",
                     dul.pdu.protocol_version)

        # Send A-ASSOCIATE-RJ PDU and start ARTIM timer
        # dul.primitive is A_ASSOCIATE
        dul.primitive.result = 0x01
        dul.primitive.result_source = 0x02
        dul.primitive.diagnostic = 0x02

        dul.pdu = A_ASSOCIATE_RJ()
        dul.pdu.FromParams(dul.primitive)

        # Callback
        dul.assoc.acse.debug_send_associate_rj(dul.pdu)

        dul.scu_socket.send(dul.pdu.Encode())

        dul.artim_timer.start()

        return 'Sta13'

    # If A-ASSOCIATE-RQ acceptable by service dul provider
    #   issue A-ASSOCIATE indication primitive and move to Sta3
    dul.to_user_queue.put(dul.primitive)

    return 'Sta3'
Ejemplo n.º 13
0
    def test_from_primitive(self):
        """ Check converting PDU to primitive """
        orig_pdu = A_ASSOCIATE_RJ()
        orig_pdu.Decode(a_associate_rj)

        primitive = orig_pdu.ToParams()

        new_pdu = A_ASSOCIATE_RJ()
        new_pdu.FromParams(primitive)

        self.assertEqual(new_pdu, orig_pdu)
Ejemplo n.º 14
0
    def test_source_str(self):
        """ Check the source str returns correct values """
        pdu = A_ASSOCIATE_RJ()
        pdu.decode(a_associate_rj)

        pdu.source = 0
        with pytest.raises(ValueError):
            pdu.source_str

        pdu.source = 1
        assert pdu.source_str == 'DUL service-user'

        pdu.source = 2
        assert pdu.source_str == 'DUL service-provider (ACSE related)'

        pdu.source = 3
        assert pdu.source_str == 'DUL service-provider (presentation related)'

        pdu.source = 4
        with pytest.raises(ValueError):
            pdu.source_str
Ejemplo n.º 15
0
    def test_result_str(self):
        """ Check the result str returns correct values """
        pdu = A_ASSOCIATE_RJ()
        pdu.decode(a_associate_rj)

        pdu.result = 0
        with pytest.raises(ValueError):
            pdu.result_str

        pdu.result = 1
        assert pdu.result_str == 'Rejected (Permanent)'

        pdu.result = 2
        assert pdu.result_str == 'Rejected (Transient)'

        pdu.result = 3
        with pytest.raises(ValueError):
            pdu.result_str
Ejemplo n.º 16
0
    def test_init(self):
        """Test a new A_ASSOCIATE_RJ PDU."""
        pdu = A_ASSOCIATE_RJ()
        assert pdu.result is None
        assert pdu.source is None
        assert pdu.reason_diagnostic is None
        assert pdu.pdu_type == 0x03
        assert pdu.pdu_length == 4
        assert len(pdu) == 10

        with pytest.raises(ValueError):
            pdu.reason_str

        with pytest.raises(ValueError):
            pdu.result_str

        with pytest.raises(ValueError):
            pdu.source_str
Ejemplo n.º 17
0
    def test_result_str(self):
        """ Check the result str returns correct values """
        pdu = A_ASSOCIATE_RJ()
        pdu.Decode(a_associate_rj)

        pdu.result = 0
        with self.assertRaises(ValueError):
            pdu.result_str

        pdu.result = 1
        self.assertEqual(pdu.result_str, 'Rejected (Permanent)')

        pdu.result = 2
        self.assertEqual(pdu.result_str, 'Rejected (Transient)')

        pdu.result = 3
        with self.assertRaises(ValueError):
            pdu.result_str
Ejemplo n.º 18
0
    def test_source_str(self):
        """ Check the source str returns correct values """
        pdu = A_ASSOCIATE_RJ()
        pdu.Decode(a_associate_rj)

        pdu.source = 0
        with self.assertRaises(ValueError):
            pdu.source_str

        pdu.source = 1
        self.assertEqual(pdu.source_str, 'DUL service-user')

        pdu.source = 2
        self.assertEqual(pdu.source_str, 'DUL service-provider (ACSE related)')

        pdu.source = 3
        self.assertEqual(pdu.source_str,
                         'DUL service-provider (presentation related)')

        pdu.source = 4
        with self.assertRaises(ValueError):
            pdu.source_str
Ejemplo n.º 19
0
    def test__pdu_to_event(self):
        """Test that good PDU paramters return expected results"""
        dul = DummyDUL()
        p2e = dul._pdu_to_event

        pdu_types = [
            A_ASSOCIATE_RQ(),
            A_ASSOCIATE_AC(),
            A_ASSOCIATE_RJ(),
            P_DATA_TF(),
            A_RELEASE_RQ(),
            A_RELEASE_RP(),
            A_ABORT_RQ(), 'TEST'
        ]
        event_str = [
            'Evt6', 'Evt3', 'Evt4', 'Evt10', 'Evt12', 'Evt13', 'Evt16', 'Evt19'
        ]

        for pdu, evt in zip(pdu_types, event_str):
            self.assertEqual(p2e(pdu), evt)
Ejemplo n.º 20
0
    def _socket_to_pdu(self, data):
        """Returns the PDU object associated with an incoming data stream.

        Parameters
        ----------
        data : bytes
            The incoming data stream

        Returns
        -------
        pdu : pynetdicom3.pdu.PDU
            The decoded data as a PDU object
        """
        pdutype = unpack('B', data[0:1])[0]
        acse = self.assoc.acse

        pdu_types = {
            0x01: (A_ASSOCIATE_RQ(), acse.debug_receive_associate_rq),
            0x02: (A_ASSOCIATE_AC(), acse.debug_receive_associate_ac),
            0x03: (A_ASSOCIATE_RJ(), acse.debug_receive_associate_rj),
            0x04: (P_DATA_TF(), acse.debug_receive_data_tf),
            0x05: (A_RELEASE_RQ(), acse.debug_receive_release_rq),
            0x06: (A_RELEASE_RP(), acse.debug_receive_release_rp),
            0x07: (A_ABORT_RQ(), acse.debug_receive_abort)
        }

        if pdutype in pdu_types:
            pdu = pdu_types[pdutype][0]
            pdu.Decode(data)

            # ACSE callbacks
            pdu_types[pdutype][1](pdu)

            return pdu

        return None
Ejemplo n.º 21
0
    def test_reason_str(self):
        """ Check the reason str returns correct values """
        pdu = A_ASSOCIATE_RJ()
        pdu.decode(a_associate_rj)

        pdu.source = 0
        with pytest.raises(ValueError):
            pdu.reason_str

        pdu.source = 1
        for ii in range(1, 11):
            pdu.reason_diagnostic = ii
            assert isinstance(pdu.reason_str, str)

        pdu.reason_diagnostic = 11
        with pytest.raises(ValueError):
            pdu.reason_str

        pdu.source = 2
        for ii in range(1, 3):
            pdu.reason_diagnostic = ii
            assert isinstance(pdu.reason_str, str)

        pdu.reason_diagnostic = 3
        with pytest.raises(ValueError):
            pdu.reason_str

        pdu.source = 3
        for ii in range(1, 8):
            pdu.reason_diagnostic = ii
            assert isinstance(pdu.reason_str, str)

        pdu.reason_diagnostic = 8
        with pytest.raises(ValueError):
            pdu.reason_str

        pdu.source = 4
        with pytest.raises(ValueError):
            pdu.reason_str
Ejemplo n.º 22
0
    def test_update_data(self):
        """ Check that updating the PDU data works correctly """
        orig_pdu = A_ASSOCIATE_RJ()
        orig_pdu.Decode(a_associate_rj)
        orig_pdu.source = 2
        orig_pdu.reason_diagnostic = 2
        orig_pdu.result = 2
        orig_pdu.get_length()

        primitive = orig_pdu.ToParams()

        new_pdu = A_ASSOCIATE_RJ()
        new_pdu.FromParams(primitive)

        self.assertEqual(new_pdu, orig_pdu)
Ejemplo n.º 23
0
 def test_string_output(self):
     """Test the string output"""
     pdu = A_ASSOCIATE_RJ()
     pdu.decode(a_associate_rj)
     assert "Rejected (Permanent)" in pdu.__str__()
     assert "DUL service-user" in pdu.__str__()
Ejemplo n.º 24
0
    def test_encode(self):
        """ Check encoding an assoc_rj produces the correct output """
        pdu = A_ASSOCIATE_RJ()
        pdu.decode(a_associate_rj)

        assert pdu.encode() == a_associate_rj