Exemple #1
0
def AA_7(dul: "DULServiceProvider") -> str:
    """Association abort AA-7.

    If receive a association request or invalid PDU while waiting for
    connection to close, send A-ABORT PDU

    State-event triggers: Sta13 + Evt6/Evt19

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

    Returns
    -------
    str
        ``'Sta13'``, the next state of the state machine
    """
    primitive = A_P_ABORT()
    primitive.provider_reason = 0x02

    # Send A-ABORT PDU
    dul._send(A_ABORT_RQ(primitive))

    return "Sta13"
Exemple #2
0
    def send_ap_abort(self, reason):
        """Send an A-P-ABORT to the peer.

        Parameters
        ----------
        reason : int
            The reason for aborting the association, one of the following:

            - ``0x00`` - reason not specified
            - ``0x01`` - unrecognised PDU
            - ``0x02`` - unexpected PDU
            - ``0x04`` - unrecognised PDU parameter
            - ``0x05`` - unexpected PDU parameter
            - ``0x06`` - invalid PDU parameter value

        Raises
        ------
        ValueError
            If the `reason` value is invalid.
        """
        if reason not in [0x00, 0x01, 0x02, 0x04, 0x05, 0x06]:
            raise ValueError("Invalid 'reason' parameter value")

        # The following parameters must be set for an A-P-ABORT primitive
        # (* sent in A-ABORT PDU):
        #    Abort Source* (always 0x02)
        #    Provider Reason*
        primitive = A_P_ABORT()
        primitive.provider_reason = reason

        self.dul.send_pdu(primitive)
        self.assoc.is_aborted = True
        self.assoc.is_established = False
Exemple #3
0
def AA_4(dul: "DULServiceProvider") -> str:
    """Association abort AA-4.

    If connection closed, issue A-P-ABORT and return to Idle

    State-event triggers: Sta3/Sta4/Sta5/Sta6/Sta7/Sta8/Sta9/Sta10/Sta11/Sta12
    + Evt17

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

    Returns
    -------
    str
        ``'Sta1'``, the next state of the state machine
    """
    assoc = dul.assoc
    assoc.dimse.msg_queue.put((None, None))

    remote = assoc.acceptor if assoc.is_requestor else assoc.requestor
    address = (remote.address, remote.port)
    evt.trigger(dul.assoc, evt.EVT_CONN_CLOSE, {"address": address})

    # Issue A-P-ABORT indication primitive.
    primitive = A_P_ABORT()
    primitive.provider_reason = 0x00
    dul.to_user_queue.put(primitive)
    dul.kill_dul()

    return "Sta1"
Exemple #4
0
def AA_7(dul):
    """Association abort AA-7.

    If receive a association request or invalid PDU while waiting for
    connection to close, send A-ABORT PDU

    State-event triggers: Sta13 + Evt6/Evt19

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

    Returns
    -------
    str
        ``'Sta13'``, the next state of the state machine
    """
    primitive = A_P_ABORT()
    primitive.provider_reason = 0x02

    # Send A-ABORT PDU.
    pdu = A_ABORT_RQ()
    pdu.from_primitive(primitive)

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

    return 'Sta13'
Exemple #5
0
    def send_ap_abort(assoc, reason):
        """Send an A-P-ABORT to the peer.

        Parameters
        ----------
        assoc : pynetdicom.association.Association
            The association that is sending the A-P-ABORT.
        reason : int
            The reason for aborting the association, one of the following:

            - 0x00 - reason not specified
            - 0x01 - unrecognised PDU
            - 0x02 - unexpected PDU
            - 0x04 - unrecognised PDU parameter
            - 0x05 - unexpected PDU parameter
            - 0x06 - invalid PDU parameter value

        Raises
        ------
        ValueError
            If the `reason` value is invalid.
        """
        if reason not in [0x00, 0x01, 0x02, 0x04, 0x05, 0x06]:
            raise ValueError("Invalid 'reason' parameter value")

        # The following parameters must be set for an A-P-ABORT primitive
        # (* sent in A-ABORT PDU):
        #    Abort Source* (always 0x02)
        #    Provider Reason*
        primitive = A_P_ABORT()
        primitive.provider_reason = reason

        assoc.dul.send_pdu(primitive)
        assoc.is_aborted = True
        assoc.is_established = False
Exemple #6
0
    def test_exceptions(self):
        """ Check incorrect types/values for properties raise exceptions """
        primitive = A_P_ABORT()

        with pytest.raises(ValueError):
            primitive.provider_reason = 3
        with pytest.raises(ValueError):
            primitive.provider_reason
Exemple #7
0
    def test_conversion(self):
        """ Check conversion to a PDU produces the correct output """
        primitive = A_P_ABORT()
        primitive.provider_reason = 4

        pdu = A_ABORT_RQ()
        pdu.from_primitive(primitive)
        data = pdu.encode()

        assert data == b"\x07\x00\x00\x00\x00\x04\x00\x00\x02\x04"
Exemple #8
0
def AA_4(dul):
    """Association abort AA-4.

    If connection closed, issue A-P-ABORT and return to Idle

    State-event triggers: Sta3/Sta4/Sta5/Sta6/Sta7/Sta8/Sta9/Sta10/Sta11/Sta12
    + Evt17

    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
        Sta1, the next state of the state machine
    """
    # Issue A-P-ABORT indication primitive.
    dul.primitive = A_P_ABORT()
    dul.primitive.provider_reason = 0x00
    dul.to_user_queue.put(dul.primitive)
    dul.kill_dul()

    return 'Sta1'
Exemple #9
0
def AA_8(dul):
    """Association abort AA-8.

    If receive invalid event, send A-ABORT, issue A-P-ABORT indication and
    start ARTIM timer

    State-event triggers: Evt3 + Sta3/6/7/8/9/10/11/12,
    Evt4 + Sta3/5/6/7/8/9/10/11/12, Evt6 + Sta3/5/6/7/8/9/10/11/12,
    Evt10 + Sta3/5/8/9/10/11/12, Evt12 + Sta3/5/8/9/10/11/12,
    Evt13 + Sta3/5/6/8/9/12, Evt19 + Sta3/5/6/7/8/9/10/11/12

    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
        Sta13, the next state of the state machine
    """
    # Send A-ABORT PDU (service-dul source), issue A-P-ABORT
    # indication, and start ARTIM timer.
    dul.pdu = A_ABORT_RQ()
    dul.pdu.source = 0x02
    dul.pdu.reason_diagnostic = 0x00

    dul.primitive = dul.pdu.to_primitive()
    dul.primitive.abort_source = 0x02
    dul.primitive.result = 0x01
    dul.primitive.diagnostic = 0x01

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

    # Issue A-P-ABORT to user
    primitive = A_P_ABORT()
    primitive.provider_reason = 0x05
    dul.to_user_queue.put(primitive)
    dul.artim_timer.start()

    return 'Sta13'
Exemple #10
0
def AA_8(dul: "DULServiceProvider") -> str:
    """Association abort AA-8.

    If receive invalid event, send A-ABORT PDU, issue A-P-ABORT indication and
    start ARTIM timer

    State-event triggers: Evt3 + Sta3/6/7/8/9/10/11/12,
    Evt4 + Sta3/5/6/7/8/9/10/11/12, Evt6 + Sta3/5/6/7/8/9/10/11/12,
    Evt10 + Sta3/5/8/9/10/11/12, Evt12 + Sta3/5/8/9/10/11/12,
    Evt13 + Sta3/5/6/8/9/12, Evt19 + Sta3/5/6/7/8/9/10/11/12

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

    Returns
    -------
    str
        ``'Sta13'``, the next state of the state machine
    """
    # Send A-ABORT PDU (service-dul source), issue A-P-ABORT
    # indication, and start ARTIM timer.
    # Send A-ABORT PDU
    pdu = A_ABORT_RQ()
    pdu.source = 0x02  # A-P-ABORT
    pdu.reason_diagnostic = 0x00

    sock = cast("AssociationSocket", dul.socket)
    sock.send(pdu.encode())
    evt.trigger(dul.assoc, evt.EVT_PDU_SENT, {'pdu': pdu})

    # Issue A-P-ABORT to user
    primitive = A_P_ABORT()
    primitive.provider_reason = 0x05
    dul.to_user_queue.put(primitive)
    dul.artim_timer.start()

    return 'Sta13'
Exemple #11
0
 def test_assignment(self):
     """ Check assignment works correctly """
     primitive = A_P_ABORT()
     primitive.provider_reason = 0
     assert primitive.provider_reason == 0
     primitive.provider_reason = 1
     assert primitive.provider_reason == 1
     primitive.provider_reason = 2
     assert primitive.provider_reason == 2
     primitive.provider_reason = 4
     assert primitive.provider_reason == 4
     primitive.provider_reason = 5
     assert primitive.provider_reason == 5
     primitive.provider_reason = 6
     assert primitive.provider_reason == 6
Exemple #12
0
def AA_4(dul):
    """Association abort AA-4.

    If connection closed, issue A-P-ABORT and return to Idle

    State-event triggers: Sta3/Sta4/Sta5/Sta6/Sta7/Sta8/Sta9/Sta10/Sta11/Sta12
    + Evt17

    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
        Sta1, the next state of the state machine
    """
    assoc = dul.assoc
    remote = assoc.acceptor if assoc.is_requestor else assoc.requestor

    address = (remote.address, remote.port)
    evt.trigger(dul.assoc, evt.EVT_CONN_CLOSE, {'address': address})

    # Issue A-P-ABORT indication primitive.
    primitive = A_P_ABORT()
    primitive.provider_reason = 0x00
    dul.to_user_queue.put(primitive)
    dul.kill_dul()

    return 'Sta1'