Example #1
0
    def test_recv_assoc_rq_user_id(self, caplog, info, output):
        """Test ACSE.debug_receive_associate_rq with User Identity."""
        with caplog.at_level(logging.DEBUG, logger='pynetdicom'):
            self.ae = ae = AE()
            ae.add_supported_context(VerificationSOPClass)
            ae.add_requested_context(VerificationSOPClass)
            scp = ae.start_server(('', 11112), block=False)
            assoc = ae.associate('localhost', 11112)

            self.add_user_identity(self.associate_rq, *info)
            pdu = A_ASSOCIATE_RQ()
            pdu.from_primitive(self.associate_rq)
            evt.trigger(assoc, evt.EVT_PDU_RECV, {'pdu': pdu})

            messages = [
                "Requested Extended Negotiation: None",
                "Requested Common Extended Negotiation: None",
                "Requested Asynchronous Operations Window Negotiation: None",
                "Requested User Identity Negotiation:",
            ]
            messages += output

            for msg in messages:
                assert msg in caplog.text

            assoc.release()
            scp.shutdown()
Example #2
0
    def test_recv_assoc_rq_sop_common(self, caplog):
        """Test ACSE.debug_receive_associate_rq with SOP Class Common."""
        with caplog.at_level(logging.DEBUG, logger='pynetdicom'):
            self.add_sop_common(self.associate_rq)
            pdu = A_ASSOCIATE_RQ()
            pdu.from_primitive(self.associate_rq)
            self.acse.debug_receive_associate_rq(pdu)

            messages = [
                "Requested Extended Negotiation: None",
                "Requested Common Extended Negotiation:",
                "SOP Class: =1.2.3.4",
                "Service Class: =1.2.3",
                "Related General SOP Classes: None",
                "SOP Class: =Verification SOP Class",
                "Service Class: =Storage Service Class",
                "Related General SOP Class(es):",
                "=CT Image Storage",
                "=1.9.1",
                "Requested Asynchronous Operations Window Negotiation: None",
                "Requested User Identity Negotiation: None",
            ]

            for msg in messages:
                assert msg in caplog.text
Example #3
0
    def test_recv_assoc_rq_minimal(self, caplog):
        """Test minimal ACSE.debug_receive_associate_rq."""
        with caplog.at_level(logging.DEBUG, logger='pynetdicom'):
            pdu = A_ASSOCIATE_RQ()
            pdu.from_primitive(self.associate_rq)
            self.acse.debug_receive_associate_rq(pdu)

            messages = [
                "Their Implementation Class UID:      1.2.826.0.1.3680043.8."
                "498.10207287587329888519122978685894984263",
                "Their Implementation Version Name:   unknown",
                "Calling Application Name:    ABCDEFGHIJKLMNOP",
                "Called Application Name:     1234567890123456",
                "Their Max PDU Receive Size:  0",
                "Presentation Contexts:",
                "Context ID:        1 (Proposed)",
                "Abstract Syntax: =1.2.3.4.5.6",
                "Proposed SCP/SCU Role: Default",
                "Proposed Transfer Syntax:",
                "=JPEG Baseline (Process 1)",
                "Context ID:        3 (Proposed)",
                "Abstract Syntax: =Verification SOP Class",
                "Proposed SCP/SCU Role: Default",
                "Proposed Transfer Syntaxes:",
                "=Implicit VR Little Endian",
                "=Explicit VR Little Endian",
                "=Explicit VR Big Endian",
                "Requested Extended Negotiation: None",
                "Requested Common Extended Negotiation: None",
                "Requested Asynchronous Operations Window Negotiation: None",
                "Requested User Identity Negotiation: None",
            ]

            for msg in messages:
                assert msg in caplog.text
Example #4
0
    def test_recv_assoc_rq_sop_common(self, caplog):
        """Test ACSE.debug_receive_associate_rq with SOP Class Common."""
        with caplog.at_level(logging.DEBUG, logger='pynetdicom'):
            self.ae = ae = AE()
            ae.add_supported_context(VerificationSOPClass)
            ae.add_requested_context(VerificationSOPClass)
            scp = ae.start_server(('', 11112), block=False)
            assoc = ae.associate('localhost', 11112)

            self.add_sop_common(self.associate_rq)
            pdu = A_ASSOCIATE_RQ()
            pdu.from_primitive(self.associate_rq)
            evt.trigger(assoc, evt.EVT_PDU_RECV, {'pdu': pdu})

            messages = [
                "Requested Extended Negotiation: None",
                "Requested Common Extended Negotiation:",
                "SOP Class: =1.2.3.4",
                "Service Class: =1.2.3",
                "Related General SOP Classes: None",
                "SOP Class: =Verification SOP Class",
                "Service Class: =Storage Service Class",
                "Related General SOP Class(es):",
                "=CT Image Storage",
                "=1.9.1",
                "Requested Asynchronous Operations Window Negotiation: None",
                "Requested User Identity Negotiation: None",
            ]

            for msg in messages:
                assert msg in caplog.text

            assoc.release()
            scp.shutdown()
Example #5
0
    def test_send_assoc_rq_sop_ext(self, caplog):
        """Test ACSE.debug_send_associate_rq with SOP Class Extended."""
        with caplog.at_level(logging.DEBUG, logger='pynetdicom'):
            self.ae = ae = AE()
            ae.add_supported_context(VerificationSOPClass)
            ae.add_requested_context(VerificationSOPClass)
            scp = ae.start_server(('', 11112), block=False)
            assoc = ae.associate('localhost', 11112)

            self.add_sop_ext(self.associate_rq)
            pdu = A_ASSOCIATE_RQ()
            pdu.from_primitive(self.associate_rq)
            evt.trigger(assoc, evt.EVT_PDU_SENT, {'pdu': pdu})

            messages = [
                "Requested Extended Negotiation:",
                "SOP Class: =1.2.3.4",
                "00  01",
                "SOP Class: =1.2.840.10008.1.1",
                "00  01  02  03  00  01  02  03  00  01  02  03  00  01  02"
                "  03",
                "00  01  02  03  00  01  02  03  00  01  02  03  00  01  02"
                "  03",
                "00  01  02  03  00  01  02  03",
                "Requested Common Extended Negotiation: None",
                "Requested Asynchronous Operations Window Negotiation: None",
                "Requested User Identity Negotiation: None",
            ]

            for msg in messages:
                assert msg in caplog.text

            assoc.release()
            scp.shutdown()
Example #6
0
    def test_send_assoc_rq_async(self, caplog):
        """Test A-ASSOCIATE-RQ with async ops."""
        with caplog.at_level(logging.DEBUG, logger='pynetdicom'):
            self.ae = ae = AE()
            ae.add_supported_context(VerificationSOPClass)
            ae.add_requested_context(VerificationSOPClass)
            scp = ae.start_server(('', 11112), block=False)
            assoc = ae.associate('localhost', 11112)

            self.add_async_ops(self.associate_rq)
            pdu = A_ASSOCIATE_RQ()
            pdu.from_primitive(self.associate_rq)
            evt.trigger(assoc, evt.EVT_PDU_SENT, {'pdu': pdu})

            messages = [
                "Requested Extended Negotiation: None",
                "Requested Common Extended Negotiation: None",
                "Requested Asynchronous Operations Window Negotiation:",
                "Maximum Invoked Operations:     2",
                "Maximum Performed Operations:   3",
                "Requested User Identity Negotiation: None",
            ]

            for msg in messages:
                assert msg in caplog.text

            assoc.release()
            scp.shutdown()
Example #7
0
def AE_2(dul):
    """Association establishment action AE-2.

    On receiving connection confirmation, send A-ASSOCIATE-RQ to the peer AE
    This send a byte stream with the format given by Table 9-11

    State-event triggers: Sta4 + Evt2

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

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

    Returns
    -------
    str
        'Sta5', the next state of the state machine.
    """
    # Send A-ASSOCIATE-RQ PDU
    dul.pdu = A_ASSOCIATE_RQ()
    dul.pdu.from_primitive(dul.primitive)

    # Callback
    LOGGER.info("Requesting Association")
    dul.assoc.acse.debug_send_associate_rq(dul.pdu)

    bytestream = dul.pdu.encode()
    dul.socket.send(bytestream)

    return 'Sta5'
Example #8
0
def AE_2(dul: "DULServiceProvider") -> str:
    """Association establishment action AE-2.

    On receiving connection confirmation, send A-ASSOCIATE-RQ to the peer AE
    This send a byte stream with the format given by Table 9-11

    State-event triggers: Sta4 + Evt2

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

    Returns
    -------
    str
        ``'Sta5'``, the next state of the state machine.
    """
    # TRANSPORT CONNECTION primitive received from transport service
    primitive = cast("T_CONNECT", dul.to_provider_queue.get(False))

    # Send A-ASSOCIATE-RQ PDU to the peer
    dul._send(A_ASSOCIATE_RQ(primitive.request))

    return "Sta5"
Example #9
0
def AE_2(dul):
    """Association establishment action AE-2.

    On receiving connection confirmation, send A-ASSOCIATE-RQ to the peer AE
    This send a byte stream with the format given by Table 9-11

    State-event triggers: Sta4 + Evt2

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

    Returns
    -------
    str
        ``'Sta5'``, the next state of the state machine.
    """
    # Send A-ASSOCIATE-RQ PDU
    dul.pdu = A_ASSOCIATE_RQ()
    dul.pdu.from_primitive(dul.primitive)

    dul.socket.send(dul.pdu.encode())
    evt.trigger(dul.assoc, evt.EVT_PDU_SENT, {'pdu': dul.pdu})

    return 'Sta5'
Example #10
0
    def test_recv_assoc_rq_user_id(self, caplog, info, output):
        """Test ACSE.debug_receive_associate_rq with User Identity."""
        with caplog.at_level(logging.DEBUG, logger='pynetdicom'):
            self.add_user_identity(self.associate_rq, *info)
            pdu = A_ASSOCIATE_RQ()
            pdu.from_primitive(self.associate_rq)
            self.acse.debug_send_associate_rq(pdu)

            messages = [
                "Requested Extended Negotiation: None",
                "Requested Common Extended Negotiation: None",
                "Requested Asynchronous Operations Window Negotiation: None",
                "Requested User Identity Negotiation:",
            ]
            messages += output

            for msg in messages:
                assert msg in caplog.text
Example #11
0
    def test_recv_assoc_rq_minimal(self, caplog):
        """Test minimal ACSE.debug_receive_associate_rq."""
        with caplog.at_level(logging.DEBUG, logger='pynetdicom'):
            self.ae = ae = AE()
            ae.add_supported_context(VerificationSOPClass)
            ae.add_requested_context(VerificationSOPClass)
            scp = ae.start_server(('', 11112), block=False)
            assoc = ae.associate('localhost', 11112)

            pdu = A_ASSOCIATE_RQ()
            pdu.from_primitive(self.associate_rq)
            evt.trigger(assoc, evt.EVT_PDU_RECV, {'pdu': pdu})

            messages = [
                "Their Implementation Class UID:      1.2.826.0.1.3680043.8."
                "498.10207287587329888519122978685894984263",
                "Their Implementation Version Name:   unknown",
                "Calling Application Name:    ABCDEFGHIJKLMNOP",
                "Called Application Name:     1234567890123456",
                "Their Max PDU Receive Size:  0",
                "Presentation Contexts:",
                "Context ID:        1 (Proposed)",
                "Abstract Syntax: =1.2.3.4.5.6",
                "Proposed SCP/SCU Role: Default",
                "Proposed Transfer Syntax:",
                "=JPEG Baseline (Process 1)",
                "Context ID:        3 (Proposed)",
                "Abstract Syntax: =Verification SOP Class",
                "Proposed SCP/SCU Role: Default",
                "Proposed Transfer Syntaxes:",
                "=Implicit VR Little Endian",
                "=Explicit VR Little Endian",
                "=Explicit VR Big Endian",
                "Requested Extended Negotiation: None",
                "Requested Common Extended Negotiation: None",
                "Requested Asynchronous Operations Window Negotiation: None",
                "Requested User Identity Negotiation: None",
            ]

            for msg in messages:
                assert msg in caplog.text

            assoc.release()
            scp.shutdown()
Example #12
0
    def test_recv_assoc_rq_async(self, caplog):
        """Test ACSE.debug_receive_associate_rq with async ops."""
        with caplog.at_level(logging.DEBUG, logger='pynetdicom'):
            self.add_async_ops(self.associate_rq)
            pdu = A_ASSOCIATE_RQ()
            pdu.from_primitive(self.associate_rq)
            self.acse.debug_receive_associate_rq(pdu)

            messages = [
                "Requested Extended Negotiation: None",
                "Requested Common Extended Negotiation: None",
                "Requested Asynchronous Operations Window Negotiation:",
                "Maximum Invoked Operations:     2",
                "Maximum Performed Operations:   3",
                "Requested User Identity Negotiation: None",
            ]

            for msg in messages:
                assert msg in caplog.text
Example #13
0
    def test_recv_assoc_rq_role(self, caplog):
        """Test ACSE.debug_receive_associate_rq with role selection."""
        with caplog.at_level(logging.DEBUG, logger='pynetdicom'):
            self.add_scp_scu_role(self.associate_rq)
            pdu = A_ASSOCIATE_RQ()
            pdu.from_primitive(self.associate_rq)
            self.acse.debug_receive_associate_rq(pdu)

            messages = [
                "Proposed SCP/SCU Role: Default",
                "Proposed SCP/SCU Role: SCU",
                "Proposed SCP/SCU Role: SCP",
                "Proposed SCP/SCU Role: SCP/SCU",
                "Requested Extended Negotiation: None",
                "Requested Common Extended Negotiation: None",
                "Requested Asynchronous Operations Window Negotiation: None",
                "Requested User Identity Negotiation: None",
            ]

            for msg in messages:
                assert msg in caplog.text
    def test_conversion(self):
        """ Check conversion to a PDU produces the correct output """
        assoc = A_ASSOCIATE()
        assoc.application_context_name = "1.2.840.10008.3.1.1.1"
        assoc.calling_ae_title = 'ECHOSCU'
        assoc.called_ae_title = 'ANY-SCP'
        assoc.maximum_length_received = 16382
        assoc.implementation_class_uid = '1.2.826.0.1.3680043.9.3811.0.9.0'

        imp_ver_name = ImplementationVersionNameNotification()
        imp_ver_name.implementation_version_name = 'PYNETDICOM_090'
        assoc.user_information.append(imp_ver_name)

        pc = PresentationContext()
        pc.context_id = 1
        pc.abstract_syntax = '1.2.840.10008.1.1'
        pc.transfer_syntax = ['1.2.840.10008.1.2']
        assoc.presentation_context_definition_list = [pc]

        pdu = A_ASSOCIATE_RQ()
        pdu.from_primitive(assoc)
        data = pdu.encode()

        assert data == (
            b"\x01\x00\x00\x00\x00\xd1\x00\x01\x00\x00\x41\x4e\x59\x2d\x53\x43"
            b"\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x45\x43\x48\x4f\x53\x43"
            b"\x55\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x00\x00\x00\x00\x00"
            b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
            b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e"
            b"\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e"
            b"\x31\x2e\x31\x20\x00\x00\x2e\x01\x00\x00\x00\x30\x00\x00\x11\x31"
            b"\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x31"
            b"\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30"
            b"\x38\x2e\x31\x2e\x32\x50\x00\x00\x3e\x51\x00\x00\x04\x00\x00\x3f"
            b"\xfe\x52\x00\x00\x20\x31\x2e\x32\x2e\x38\x32\x36\x2e\x30\x2e\x31"
            b"\x2e\x33\x36\x38\x30\x30\x34\x33\x2e\x39\x2e\x33\x38\x31\x31\x2e"
            b"\x30\x2e\x39\x2e\x30\x55\x00\x00\x0e\x50\x59\x4e\x45\x54\x44\x49"
            b"\x43\x4f\x4d\x5f\x30\x39\x30"
        )
Example #15
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):
            assert p2e(pdu) == evt
Example #16
0
    def test_recv_assoc_rq_sop_ext(self, caplog):
        """Test ACSE.debug_receive_associate_rq with SOP Class Extended."""
        with caplog.at_level(logging.DEBUG, logger='pynetdicom'):
            self.add_sop_ext(self.associate_rq)
            pdu = A_ASSOCIATE_RQ()
            pdu.from_primitive(self.associate_rq)
            self.acse.debug_receive_associate_rq(pdu)

            messages = [
                "Requested Extended Negotiation:",
                "SOP Class: =1.2.3.4",
                "[ 00  01 ]",
                "SOP Class: =1.2.840.10008.1.1",
                "[ 00  01  02  03  00  01  02  03  00  01  02  03  00  01  02"
                "  03",
                "00  01  02  03  00  01  02  03  00  01  02  03  00  01  02  03",
                "00  01  02  03  00  01  02  03 ]",
                "Requested Common Extended Negotiation: None",
                "Requested Asynchronous Operations Window Negotiation: None",
                "Requested User Identity Negotiation: None",
            ]

            for msg in messages:
                assert msg in caplog.text