Coverage Report - org.jscsi.target.connection.phase.TargetFullFeaturePhase
 
Classes in this File Line Coverage Branch Coverage Complexity
TargetFullFeaturePhase
0%
0/61
0%
0/31
9.333
TargetFullFeaturePhase$1
0%
0/2
N/A
9.333
 
 1  
 package org.jscsi.target.connection.phase;
 2  
 
 3  
 
 4  
 import java.io.IOException;
 5  
 import java.security.DigestException;
 6  
 
 7  
 import javax.naming.OperationNotSupportedException;
 8  
 
 9  
 import org.jscsi.exception.InternetSCSIException;
 10  
 import org.jscsi.parser.BasicHeaderSegment;
 11  
 import org.jscsi.parser.ProtocolDataUnit;
 12  
 import org.jscsi.parser.scsi.SCSICommandParser;
 13  
 import org.jscsi.target.connection.Connection;
 14  
 import org.jscsi.target.connection.stage.TMStage;
 15  
 import org.jscsi.target.connection.stage.fullfeature.FormatUnitStage;
 16  
 import org.jscsi.target.connection.stage.fullfeature.InquiryStage;
 17  
 import org.jscsi.target.connection.stage.fullfeature.LogoutStage;
 18  
 import org.jscsi.target.connection.stage.fullfeature.ModeSenseStage;
 19  
 import org.jscsi.target.connection.stage.fullfeature.PingStage;
 20  
 import org.jscsi.target.connection.stage.fullfeature.ReadCapacityStage;
 21  
 import org.jscsi.target.connection.stage.fullfeature.ReadStage;
 22  
 import org.jscsi.target.connection.stage.fullfeature.ReportLunsStage;
 23  
 import org.jscsi.target.connection.stage.fullfeature.RequestSenseStage;
 24  
 import org.jscsi.target.connection.stage.fullfeature.SendDiagnosticStage;
 25  
 import org.jscsi.target.connection.stage.fullfeature.TargetFullFeatureStage;
 26  
 import org.jscsi.target.connection.stage.fullfeature.TestUnitReadyStage;
 27  
 import org.jscsi.target.connection.stage.fullfeature.TextNegotiationStage;
 28  
 import org.jscsi.target.connection.stage.fullfeature.UnsupportedOpCodeStage;
 29  
 import org.jscsi.target.connection.stage.fullfeature.WriteStage;
 30  
 import org.jscsi.target.scsi.cdb.ScsiOperationCode;
 31  
 import org.jscsi.target.settings.SettingsException;
 32  
 import org.slf4j.Logger;
 33  
 import org.slf4j.LoggerFactory;
 34  
 
 35  
 
 36  
 /**
 37  
  * Objects of this class represent the Target Full Feature Phase of a connection.
 38  
  * 
 39  
  * @see TargetPhase
 40  
  * @author Andreas Ergenzinger
 41  
  */
 42  
 public final class TargetFullFeaturePhase extends TargetPhase {
 43  
 
 44  0
     private static final Logger LOGGER = LoggerFactory.getLogger(TargetFullFeaturePhase.class);
 45  
 
 46  
     /**
 47  
      * The current stage of this phase.
 48  
      */
 49  
     private TargetFullFeatureStage stage;
 50  
 
 51  
     /**
 52  
      * While this variable is <code>true</code> the phase is still running, either executing a specific stage or waiting
 53  
      * for the next one to begin.
 54  
      */
 55  
     private boolean running;
 56  
 
 57  
     /**
 58  
      * The constructor.
 59  
      * 
 60  
      * @param connection {@inheritDoc}
 61  
      */
 62  
     public TargetFullFeaturePhase (Connection connection) {
 63  0
         super(connection);
 64  
 
 65  0
     }
 66  
 
 67  
     /**
 68  
      * Starts the full feature phase.
 69  
      * 
 70  
      * @return {@inheritDoc}
 71  
      * @throws OperationNotSupportedException {@inheritDoc}
 72  
      * @throws IOException {@inheritDoc}
 73  
      * @throws InterruptedException {@inheritDoc}
 74  
      * @throws InternetSCSIException {@inheritDoc}
 75  
      * @throws DigestException {@inheritDoc}
 76  
      * @throws SettingsException {@inheritDoc}
 77  
      */
 78  
     public boolean execute () throws DigestException , IOException , InterruptedException , InternetSCSIException , SettingsException {
 79  
 
 80  0
         running = true;
 81  0
         while (running) {
 82  0
             ProtocolDataUnit pdu = connection.receivePdu();
 83  0
             BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();
 84  
 
 85  
             // identify desired stage
 86  0
             switch (bhs.getOpCode()) {
 87  
 
 88  
                 case SCSI_COMMAND :
 89  0
                     if (connection.getTargetSession().isNormalSession()) {
 90  0
                         final SCSICommandParser parser = (SCSICommandParser) bhs.getParser();
 91  0
                         ScsiOperationCode scsiOpCode = ScsiOperationCode.valueOf(parser.getCDB().get(0));
 92  
 
 93  0
                         LOGGER.debug("scsiOpCode = " + scsiOpCode);// log SCSI
 94  
                                                                    // Operation Code
 95  
 
 96  0
                         if (scsiOpCode != null) {
 97  0
                             switch (scsiOpCode) {
 98  
                                 case TEST_UNIT_READY :
 99  0
                                     stage = new TestUnitReadyStage(this);
 100  0
                                     break;
 101  
                                 case REQUEST_SENSE :
 102  0
                                     stage = new RequestSenseStage(this);
 103  0
                                     break;
 104  
                                 case FORMAT_UNIT :
 105  0
                                     stage = new FormatUnitStage(this);
 106  0
                                     break;
 107  
                                 case INQUIRY :
 108  0
                                     stage = new InquiryStage(this);
 109  0
                                     break;
 110  
                                 case MODE_SELECT_6 :
 111  0
                                     stage = null;
 112  0
                                     scsiOpCode = null;
 113  0
                                     break;
 114  
                                 case MODE_SENSE_6 :
 115  0
                                     stage = new ModeSenseStage(this);
 116  0
                                     if (!((ModeSenseStage) stage).canHandle(pdu)) {
 117  0
                                         stage = null;
 118  0
                                         scsiOpCode = null;
 119  
                                     }
 120  
                                     break;
 121  
                                 case SEND_DIAGNOSTIC :
 122  0
                                     stage = new SendDiagnosticStage(this);
 123  0
                                     break;
 124  
                                 case READ_CAPACITY_10 :// use common read capacity stage
 125  
                                 case READ_CAPACITY_16 :
 126  0
                                     stage = new ReadCapacityStage(this);
 127  0
                                     break;
 128  
                                 case WRITE_6 :// use common write stage
 129  
                                 case WRITE_10 :
 130  0
                                     stage = new WriteStage(this);
 131  0
                                     break;
 132  
                                 case READ_6 :// use common read stage
 133  
                                 case READ_10 :
 134  0
                                     stage = new ReadStage(this);
 135  0
                                     break;
 136  
                                 case REPORT_LUNS :
 137  0
                                     stage = new ReportLunsStage(this);
 138  0
                                     break;
 139  
                                 default :
 140  0
                                     scsiOpCode = null;
 141  
 
 142  
                             }
 143  
                         }// else, or if default block was entered (programmer error)
 144  0
                         if (scsiOpCode == null) {
 145  0
                             LOGGER.error("Unsupported SCSI OpCode 0x" + Integer.toHexString(parser.getCDB().get(0) & 255) + " in SCSI Command PDU.");
 146  0
                             stage = new UnsupportedOpCodeStage(this);
 147  
                         }
 148  
 
 149  0
                     } else {// session is discovery session
 150  0
                         throw new InternetSCSIException("received SCSI command in discovery session");
 151  
                     }
 152  
                     break; // SCSI_COMMAND
 153  
 
 154  
                 case SCSI_TM_REQUEST :
 155  0
                     stage = new TMStage(this);
 156  0
                     break;
 157  
                 case NOP_OUT :
 158  0
                     stage = new PingStage(this);
 159  0
                     break;
 160  
                 case TEXT_REQUEST :
 161  0
                     stage = new TextNegotiationStage(this);
 162  0
                     break;
 163  
                 case LOGOUT_REQUEST :
 164  0
                     stage = new LogoutStage(this);
 165  0
                     running = false;
 166  0
                     break;
 167  
                 default :
 168  0
                     LOGGER.error("Recieved unsupported opcode for " + pdu.getBasicHeaderSegment().getOpCode());
 169  0
                     stage = new UnsupportedOpCodeStage(this);
 170  
             }
 171  
 
 172  
             // process the PDU
 173  0
             stage.execute(pdu);
 174  0
         }
 175  
 
 176  0
         return false;
 177  
     }
 178  
     
 179  
     /**
 180  
      * Stopping this phases execution
 181  
      */
 182  
     public void stop(){
 183  0
         this.running = false;
 184  0
     }
 185  
 }