1 package org.jscsi.target.connection.stage.fullfeature;
2
3
4 import java.io.IOException;
5 import java.nio.ByteBuffer;
6 import java.security.DigestException;
7
8 import org.jscsi.exception.InternetSCSIException;
9 import org.jscsi.parser.BasicHeaderSegment;
10 import org.jscsi.parser.ProtocolDataUnit;
11 import org.jscsi.parser.nop.NOPOutParser;
12 import org.jscsi.target.connection.TargetPduFactory;
13 import org.jscsi.target.connection.phase.TargetFullFeaturePhase;
14 import org.jscsi.target.settings.SettingsException;
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 public class PingStage extends TargetFullFeatureStage {
31
32 private static final int RESERVED_TAG_VALUE = 0xffffffff;
33
34 public PingStage (TargetFullFeaturePhase targetFullFeaturePhase) {
35 super(targetFullFeaturePhase);
36 }
37
38 @Override
39 public void execute (final ProtocolDataUnit pdu) throws IOException , InterruptedException , InternetSCSIException , DigestException , SettingsException {
40
41 final BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();
42 final NOPOutParser parser = (NOPOutParser) bhs.getParser();
43
44 if (parser.getTargetTransferTag() != RESERVED_TAG_VALUE) {
45
46
47
48
49
50
51 throw new InternetSCSIException("NOP-Out PDU TargetTransferTag = " + parser.getTargetTransferTag() + " in PingStage");
52 }
53
54
55 if (bhs.getInitiatorTaskTag() == RESERVED_TAG_VALUE) return;
56
57
58
59
60 final int dataSegmentLength = Math.min(pdu.getDataSegment().capacity(), settings.getMaxRecvDataSegmentLength());
61 final ByteBuffer responseDataSegment = ByteBuffer.allocate(dataSegmentLength);
62 responseDataSegment.put(pdu.getDataSegment().array(),
63 0,
64 dataSegmentLength);
65
66
67 final ProtocolDataUnit responsePdu = TargetPduFactory.createNopInPDU(0,
68
69 bhs.getInitiatorTaskTag(),
70 RESERVED_TAG_VALUE,
71 responseDataSegment, parser.getExpectedStatusSequenceNumber());
72 connection.sendPdu(responsePdu);
73 }
74
75 }