View Javadoc

1   package org.jscsi.target.connection.stage;
2   
3   
4   import java.io.IOException;
5   import java.security.DigestException;
6   
7   import org.jscsi.exception.InternetSCSIException;
8   import org.jscsi.parser.BasicHeaderSegment;
9   import org.jscsi.parser.ProtocolDataUnit;
10  import org.jscsi.parser.tmf.TaskManagementFunctionRequestParser;
11  import org.jscsi.parser.tmf.TaskManagementFunctionResponseParser;
12  import org.jscsi.parser.tmf.TaskManagementFunctionResponseParser.ResponseCode;
13  import org.jscsi.target.connection.TargetPduFactory;
14  import org.jscsi.target.connection.phase.TargetFullFeaturePhase;
15  import org.jscsi.target.connection.stage.fullfeature.TargetFullFeatureStage;
16  import org.jscsi.target.settings.SettingsException;
17  import org.slf4j.Logger;
18  import org.slf4j.LoggerFactory;
19  
20  
21  /**
22   * A stage for processing Task Management Function Request defined in RFC(7320).
23   * 
24   * Warning, this class is only a dummy to react on the request without functionality except for response.
25   * 
26   * @author Andreas Rain
27   */
28  public class TMStage extends TargetFullFeatureStage {
29  
30      private static final Logger LOGGER = LoggerFactory.getLogger(TMStage.class);
31  
32      /**
33       * @param targetFullFeaturePhase
34       */
35      public TMStage (TargetFullFeaturePhase targetFullFeaturePhase) {
36          super(targetFullFeaturePhase);
37      }
38  
39      @Override
40      public void execute (ProtocolDataUnit pdu) throws IOException , InterruptedException , InternetSCSIException , DigestException , SettingsException {
41  
42          final BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();
43          final TaskManagementFunctionRequestParser parser = (TaskManagementFunctionRequestParser) bhs.getParser();
44          final int initiatorTaskTag = bhs.getInitiatorTaskTag();
45  
46          TaskManagementFunctionResponseParser.ResponseCode responseCode = ResponseCode.TASK_DOES_NOT_EXIST;
47  
48          switch (parser.getFunction()) {
49              case ABORT_TASK :
50                  LOGGER.error("ABORT_TASK");
51                  break;
52              case ABORT_TASK_SET :
53                  LOGGER.error("ABORT_TASK_SET");
54                  break;
55              case CLEAR_ACA :
56                  responseCode = ResponseCode.FUNCTION_COMPLETE;
57                  break;
58              case CLEAR_TASK_SET :
59                  responseCode = ResponseCode.FUNCTION_COMPLETE;
60                  break;
61              case LUN_RESET :
62                  LOGGER.error("LUN_RESET");
63                  break;
64              case TARGET_WARM_RESET :
65                  LOGGER.error("TARGET_WARM_RESET");
66                  break;
67              case TARGET_COLD_RESET :
68                  LOGGER.error("TARGET_COLD_RESET");
69                  break;
70              case TASK_REASSIGN :
71                  LOGGER.error("TASK_REASSIGN");
72                  break;
73              default :
74                  break;
75          }
76  
77          final ProtocolDataUnit responsePDU = TargetPduFactory.createTMResponsePdu(responseCode, initiatorTaskTag);
78          connection.sendPdu(responsePDU);
79  
80      }
81  
82  }