def test_a_p_abort_from_primitive(self): """ Check converting PDU to primitive """ orig_pdu = A_ABORT_RQ() orig_pdu.decode(a_p_abort) primitive = orig_pdu.to_primitive() new_pdu = A_ABORT_RQ() new_pdu.from_primitive(primitive) assert new_pdu == orig_pdu
def test_a_p_abort_from_primitive(self): """ Check converting PDU to primitive """ orig_pdu = A_ABORT_RQ() orig_pdu.Decode(a_p_abort) primitive = orig_pdu.ToParams() new_pdu = A_ABORT_RQ() new_pdu.FromParams(primitive) self.assertEqual(new_pdu, orig_pdu)
def test_string_output(self): """Test the string output""" pdu = A_ABORT_RQ() pdu.decode(a_abort) assert "0x07" in pdu.__str__() assert "4 bytes" in pdu.__str__() assert "DUL service-user" in pdu.__str__()
def test_string_output(self): """Test the string output""" pdu = A_ABORT_RQ() pdu.Decode(a_abort) self.assertTrue("0x07" in pdu.__str__()) self.assertTrue("4 bytes" in pdu.__str__()) self.assertTrue("DUL service-user" in pdu.__str__())
def test_new_encode_a_p_abort(self): """ Check encoding using new generic method """ pdu = A_ABORT_RQ() pdu.Decode(a_p_abort) s = pdu.encode() self.assertEqual(s, a_p_abort)
def test_a_p_abort_stream_encode(self): """ Check encoding an a_abort produces the correct output """ pdu = A_ABORT_RQ() pdu.Decode(a_p_abort) s = pdu.Encode() self.assertEqual(s, a_p_abort)
def AA_7(dul): """Association abort AA-7. If receive a association request or invalid PDU while waiting for connection to close, issue A-ABORT State-event triggers: Sta13 + Evt6/Evt19 .. [1] DICOM Standard 2015b, PS3.8, Table 9-9, "Associate Abort 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-ABORT PDU. dul.pdu = A_ABORT_RQ() dul.pdu.FromParams(dul.primitive) # Callback dul.assoc.acse.debug_send_abort(dul.pdu) dul.scu_socket.send(dul.pdu.Encode()) return 'Sta13'
def test_generic_encode(self): """ Check using the new pdu.encode produces the correct output """ pdu = A_ABORT_RQ() pdu.Decode(a_abort) s = pdu.Encode() t = pdu.encode() self.assertEqual(s, t)
def test_to_a_p_abort_primitive(self): """ Check converting PDU to a_p_abort primitive """ pdu = A_ABORT_RQ() pdu.decode(a_p_abort) primitive = pdu.to_primitive() assert isinstance(primitive, A_P_ABORT) assert primitive.provider_reason == 4
def test_a_p_abort_decode(self): """ Check decoding the a_abort stream produces the correct objects """ pdu = A_ABORT_RQ() pdu.decode(a_p_abort) assert pdu.pdu_type == 0x07 assert pdu.pdu_length == 4 assert pdu.source == 2 assert pdu.reason_diagnostic == 4
def test_to_a_p_abort_primitive(self): """ Check converting PDU to a_p_abort primitive """ pdu = A_ABORT_RQ() pdu.Decode(a_p_abort) primitive = pdu.ToParams() self.assertTrue(isinstance(primitive, A_P_ABORT)) self.assertEqual(primitive.provider_reason, 4)
def test_to_a_abort_primitive(self): """ Check converting PDU to a_abort primitive """ pdu = A_ABORT_RQ() pdu.decode(a_abort) primitive = pdu.to_primitive() assert isinstance(primitive, A_ABORT) assert primitive.abort_source == 0
def test_source_str(self): """ Check the source str returns correct values """ pdu = A_ABORT_RQ() pdu.decode(a_abort) pdu.source = 0 assert pdu.source_str == 'DUL service-user' pdu.source = 2 assert pdu.source_str == 'DUL service-provider'
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() self.assertEqual(data, b"\x07\x00\x00\x00\x00\x04\x00\x00\x02\x04")
def test_source_str(self): """ Check the source str returns correct values """ pdu = A_ABORT_RQ() pdu.Decode(a_abort) pdu.source = 0 self.assertEqual(pdu.source_str, 'DUL service-user') pdu.source = 2 self.assertEqual(pdu.source_str, 'DUL service-provider')
def test_conversion(self): """ Check conversion to a PDU produces the correct output """ primitive = A_ABORT() primitive.abort_source = 0 pdu = A_ABORT_RQ() pdu.from_primitive(primitive) data = pdu.encode() self.assertEqual(data, b"\x07\x00\x00\x00\x00\x04\x00\x00\x00\x00")
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 : 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-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 if dul.scu_socket: # Callback dul.assoc.acse.debug_send_abort(dul.pdu) try: # Encode and send A-ABORT to peer dul.scu_socket.send(dul.pdu.encode()) except socket.error: dul.scu_socket.close() except ConnectionResetError: dul.scu_socket.close() # Issue A-P-ABORT to user dul.to_user_queue.put(dul.primitive) dul.artim_timer.start() return 'Sta13'
def test_a_p_abort_stream_decode_values_types(self): """ Check decoding the a_abort stream produces the correct objects """ pdu = A_ABORT_RQ() pdu.Decode(a_p_abort) self.assertEqual(pdu.pdu_type, 0x07) self.assertEqual(pdu.pdu_length, 4) self.assertEqual(pdu.source, 2) self.assertEqual(pdu.reason_diagnostic, 4) self.assertTrue(isinstance(pdu.pdu_type, int)) self.assertTrue(isinstance(pdu.pdu_length, int)) self.assertTrue(isinstance(pdu.source, int)) self.assertTrue(isinstance(pdu.reason_diagnostic, int))
def test_init(self): """Test a new A_ABORT_RQ PDU""" pdu = A_ABORT_RQ() assert pdu.pdu_type == 0x07 assert pdu.pdu_length == 4 assert len(pdu) == 10 assert pdu.source is None assert pdu.reason_diagnostic is None with pytest.raises(KeyError): pdu.source_str pdu.reason_str == 'No reason given'
def AA_1(dul): """Association abort AA-1. If on sending A-ASSOCIATE-RQ we receive an invalid reply, or an abort request then abort State-event triggers: Sta2 + Evt3/Evt4/Evt10/Evt12/Evt13/Evt19, Sta3/Sta5/Sta6/Sta7/Sta8/Sta9/Sta10/Sta11/Sta12 + Evt15 References ---------- 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-ABORT PDU (service-user source) and start (or restart # if already started) ARTIM timer. dul.pdu = A_ABORT_RQ() dul.pdu.source = 0x00 # The reason for the abort should really be roughly defined by the # current state of the State Machine if dul.state_machine.current_state == 'Sta2': # Unexpected PDU dul.pdu.reason_diagnostic = 0x02 else: # Reason not specified dul.pdu.reason_diagnostic = 0x00 dul.pdu.from_primitive(dul.primitive) # Callback dul.assoc.acse.debug_send_abort(dul.pdu) dul.scu_socket.send(dul.pdu.encode()) dul.artim_timer.restart() return 'Sta13'
def test_reason_str(self): """ Check the reaspm str returns correct values """ pdu = A_ABORT_RQ() pdu.Decode(a_abort) pdu.source = 2 pdu.reason_diagnostic = 0 self.assertEqual(pdu.reason_str, "No reason given") pdu.reason_diagnostic = 1 self.assertEqual(pdu.reason_str, "Unrecognised PDU") pdu.reason_diagnostic = 2 self.assertEqual(pdu.reason_str, "Unexpected PDU") pdu.reason_diagnostic = 3 self.assertEqual(pdu.reason_str, "Reserved") pdu.reason_diagnostic = 4 self.assertEqual(pdu.reason_str, "Unrecognised PDU parameter") pdu.reason_diagnostic = 5 self.assertEqual(pdu.reason_str, "Unexpected PDU parameter") pdu.reason_diagnostic = 6 self.assertEqual(pdu.reason_str, "Invalid PDU parameter value")
def test_reason_str(self): """ Check the reaspm str returns correct values """ pdu = A_ABORT_RQ() pdu.decode(a_abort) pdu.source = 2 pdu.reason_diagnostic = 0 assert pdu.reason_str == "No reason given" pdu.reason_diagnostic = 1 assert pdu.reason_str == "Unrecognised PDU" pdu.reason_diagnostic = 2 assert pdu.reason_str == "Unexpected PDU" pdu.reason_diagnostic = 3 assert pdu.reason_str == "Reserved" pdu.reason_diagnostic = 4 assert pdu.reason_str == "Unrecognised PDU parameter" pdu.reason_diagnostic = 5 assert pdu.reason_str == "Unexpected PDU parameter" pdu.reason_diagnostic = 6 assert pdu.reason_str == "Invalid PDU parameter value"
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)
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
def test_a_p_abort_encode(self): """ Check encoding an a_abort produces the correct output """ pdu = A_ABORT_RQ() pdu.decode(a_p_abort) assert pdu.encode() == a_p_abort