Package org.jscsi.parser

Examples of org.jscsi.parser.ProtocolDataUnit


                // deactivate Nagle algorithm
                socketChannel.socket().setTcpNoDelay(true);

                connection = new TargetConnection(socketChannel, true);
                try {
                    final ProtocolDataUnit pdu = connection.receivePdu();
                    // confirm OpCode-
                    if (pdu.getBasicHeaderSegment().getOpCode() != OperationCode.LOGIN_REQUEST) throw new InternetSCSIException();
                    // get initiatorSessionID
                   
                    LoginRequestParser parser = (LoginRequestParser) pdu.getBasicHeaderSegment().getParser();
                    ISID initiatorSessionID = parser.getInitiatorSessionID();

                    /*
                     * TODO get (new or existing) session based on TSIH But since we don't do session reinstatement and
                     * MaxConnections=1, we can just create a new one.
View Full Code Here


    static ScsiResponseDataSegment nonEmpty;

    @BeforeClass
    public void beforeClass () {

        /**
         * The following part simulates a none-empty ScsiResponseDataSegment. It's copied for the most part from the
         * RequestSenseStage
         */

        final ProtocolDataUnit pdu = new ProtocolDataUnitFactory().create(false, true, OperationCode.LOGIN_REQUEST, "None", "None");
View Full Code Here

     * @throws InternetSCSIException if any violation of the iSCSI-Standard emerge.
     * @throws DigestException if a mismatch of the digest exists.
     */
    public ProtocolDataUnit receiveFromWire () throws DigestException , InternetSCSIException , IOException {

        final ProtocolDataUnit protocolDataUnit = protocolDataUnitFactory.create(connection.getSetting(OperationalTextKey.HEADER_DIGEST), connection.getSetting(OperationalTextKey.DATA_DIGEST));

        try {
            protocolDataUnit.read(socketChannel);
        } catch (ClosedChannelException e) {
            throw new InternetSCSIException(e);
        }

        LOGGER.debug("Receiving this PDU: " + protocolDataUnit);

        final Exception isCorrect = connection.getState().isCorrect(protocolDataUnit);
        if (isCorrect == null) {
            LOGGER.trace("Adding PDU to Receiving Queue.");

            final TargetMessageParser parser = (TargetMessageParser) protocolDataUnit.getBasicHeaderSegment().getParser();
            final Session session = connection.getSession();

            // the PDU maxCmdSN is greater than the local maxCmdSN, so we
            // have to update the local one
            if (session.getMaximumCommandSequenceNumber().compareTo(parser.getMaximumCommandSequenceNumber()) < 0) {
View Full Code Here

     */
    public boolean execute () throws DigestException , IOException , InterruptedException , InternetSCSIException , SettingsException {

        running = true;
        while (running) {
            ProtocolDataUnit pdu = connection.receivePdu();
            BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();

            // identify desired stage
            switch (bhs.getOpCode()) {

                case SCSI_COMMAND :
                    if (connection.getTargetSession().isNormalSession()) {
                        final SCSICommandParser parser = (SCSICommandParser) bhs.getParser();
                        ScsiOperationCode scsiOpCode = ScsiOperationCode.valueOf(parser.getCDB().get(0));

                        LOGGER.debug("scsiOpCode = " + scsiOpCode);// log SCSI
                                                                   // Operation Code

                        if (scsiOpCode != null) {
                            switch (scsiOpCode) {
                                case TEST_UNIT_READY :
                                    stage = new TestUnitReadyStage(this);
                                    break;
                                case REQUEST_SENSE :
                                    stage = new RequestSenseStage(this);
                                    break;
                                case FORMAT_UNIT :
                                    stage = new FormatUnitStage(this);
                                    break;
                                case INQUIRY :
                                    stage = new InquiryStage(this);
                                    break;
                                case MODE_SELECT_6 :
                                    stage = null;
                                    scsiOpCode = null;
                                    break;
                                case MODE_SENSE_6 :
                                    stage = new ModeSenseStage(this);
                                    if (!((ModeSenseStage) stage).canHandle(pdu)) {
                                        stage = null;
                                        scsiOpCode = null;
                                    }
                                    break;
                                case SEND_DIAGNOSTIC :
                                    stage = new SendDiagnosticStage(this);
                                    break;
                                case READ_CAPACITY_10 :// use common read capacity stage
                                case READ_CAPACITY_16 :
                                    stage = new ReadCapacityStage(this);
                                    break;
                                case WRITE_6 :// use common write stage
                                case WRITE_10 :
                                    stage = new WriteStage(this);
                                    break;
                                case READ_6 :// use common read stage
                                case READ_10 :
                                    stage = new ReadStage(this);
                                    break;
                                case REPORT_LUNS :
                                    stage = new ReportLunsStage(this);
                                    break;
                                default :
                                    scsiOpCode = null;

                            }
                        }// else, or if default block was entered (programmer error)
                        if (scsiOpCode == null) {
                            LOGGER.error("Unsupported SCSI OpCode 0x" + Integer.toHexString(parser.getCDB().get(0) & 255) + " in SCSI Command PDU.");
                            stage = new UnsupportedOpCodeStage(this);
                        }

                    } else {// session is discovery session
                        throw new InternetSCSIException("received SCSI command in discovery session");
                    }
                    break; // SCSI_COMMAND

                case SCSI_TM_REQUEST :
                    stage = new TMStage(this);
                    break;
                case NOP_OUT :
                    stage = new PingStage(this);
                    break;
                case TEXT_REQUEST :
                    stage = new TextNegotiationStage(this);
                    break;
                case LOGOUT_REQUEST :
                    stage = new LogoutStage(this);
                    running = false;
                    break;
                default :
                    LOGGER.error("Recieved unsupported opcode for " + pdu.getBasicHeaderSegment().getOpCode());
                    stage = new UnsupportedOpCodeStage(this);
            }

            // process the PDU
            stage.execute(pdu);
View Full Code Here

    // --------------------------------------------------------------------------

    /** {@inheritDoc} */
    public final void execute () throws InternetSCSIException {

        final ProtocolDataUnit protocolDataUnit = protocolDataUnitFactory.create(false, true, OperationCode.TEXT_REQUEST, connection.getSetting(OperationalTextKey.HEADER_DIGEST), connection.getSetting(OperationalTextKey.DATA_DIGEST));
        final TextRequestParser parser = (TextRequestParser) protocolDataUnit.getBasicHeaderSegment().getParser();

        final SettingsMap settings = new SettingsMap();
        settings.add(OperationalTextKey.SEND_TARGETS, "");

        final IDataSegment dataSegment = DataSegmentFactory.create(settings.asByteBuffer(), DataSegmentFormat.TEXT, connection.getSettingAsInt(OperationalTextKey.MAX_RECV_DATA_SEGMENT_LENGTH));

        int bytes2Process = dataSegment.getLength();
        for (IDataSegmentIterator dataSegmentIterator = dataSegment.iterator(); dataSegmentIterator.hasNext();) {
            IDataSegmentChunk dataSegmentChunk = dataSegmentIterator.next(bytes2Process);
            protocolDataUnit.setDataSegment(dataSegmentChunk);
            parser.setTargetTransferTag(0xFFFFFFFF);
        }

        connection.send(protocolDataUnit);
        connection.nextState(new GetConnectionsResponseState(connection));
View Full Code Here

            true,// commandData (i.e. invalid field in CDB)
            false,// bitPointerValid
            0,// bitPointer, reserved since invalid
            0);// fieldPointer to the SCSI OpCode field
            final FieldPointerSenseKeySpecificData[] fpArray = new FieldPointerSenseKeySpecificData[] { fp };
            final ProtocolDataUnit responsePdu = createFixedFormatErrorPdu(fpArray,// senseKeySpecificData
                    AdditionalSenseCodeAndQualifier.LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE,// additionalSenseCodeAndQualifier
                    bhs.getInitiatorTaskTag(),// initiatorTaskTag
                    parser.getExpectedDataTransferLength());// expectedDataTransferLength
            connection.sendPdu(responsePdu);
            return;
View Full Code Here

    // --------------------------------------------------------------------------

    /** {@inheritDoc} */
    public final void execute () throws InternetSCSIException {

        final ProtocolDataUnit protocolDataUnit = protocolDataUnitFactory.create(false, true, OperationCode.SCSI_COMMAND, connection.getSetting(OperationalTextKey.HEADER_DIGEST), connection.getSetting(OperationalTextKey.DATA_DIGEST));
        final SCSICommandParser scsi = (SCSICommandParser) protocolDataUnit.getBasicHeaderSegment().getParser();

        scsi.setReadExpectedFlag(true);
        scsi.setWriteExpectedFlag(false);
        scsi.setTaskAttributes(taskAttributes);
        scsi.setExpectedDataTransferLength(expectedDataTransferLength);
View Full Code Here

    // --------------------------------------------------------------------------

    /** {@inheritDoc} */
    public final void execute () throws InternetSCSIException {

        ProtocolDataUnit protocolDataUnit;
        final IDataSegment loginResponse = DataSegmentFactory.create(DataSegmentFormat.TEXT, connection.getSettingAsInt(OperationalTextKey.MAX_RECV_DATA_SEGMENT_LENGTH));

        do {
            protocolDataUnit = connection.receive();

            if (!(protocolDataUnit.getBasicHeaderSegment().getParser() instanceof LoginResponseParser)) {
                break;
            }

            loginResponse.append(protocolDataUnit.getDataSegment(), protocolDataUnit.getBasicHeaderSegment().getDataSegmentLength());
        } while (!protocolDataUnit.getBasicHeaderSegment().isFinalFlag());
        // extract Target Session Handle Identifying Handle
        final LoginResponseParser parser = (LoginResponseParser) protocolDataUnit.getBasicHeaderSegment().getParser();
        connection.getSession().setTargetSessionIdentifyingHandle(parser.getTargetSessionIdentifyingHandle());
        // Set the Expected Status Sequence Number to the initial value received
        // from the target. Then add the constant 2 to this value, because the
        // incrementExpectedStatusSequence() method was already invoked.
        connection.setExpectedStatusSequenceNumber(parser.getStatusSequenceNumber() + 1);// TODO was +2

        // check parameters....
        LOGGER.info("Retrieving these login parameters:\n" + loginResponse.getSettings());

        connection.update(loginResponse.getSettings());

        LOGGER.info("Updated settings to these:\n" + connection.getSettings());
        LOGGER.info("Nextstage is : " + nextStage);

        // is a transit to the next stage possible
        if (protocolDataUnit.getBasicHeaderSegment().isFinalFlag()) {
            if (nextStage == LoginStage.LOGIN_OPERATIONAL_NEGOTIATION) {
                connection.getSession().setPhase(new LoginOperationalNegotiationPhase());
            } else if (nextStage == LoginStage.FULL_FEATURE_PHASE) {
                connection.getSession().setPhase(new FullFeaturePhase());
                // return false;
View Full Code Here

        final boolean residualOverflow = expectedDataTransferLength < fullBuffer.capacity();
        final boolean residualUnderflow = expectedDataTransferLength > fullBuffer.capacity();
        final int residualCount = Math.abs(expectedDataTransferLength - fullBuffer.capacity());

        // create and send PDU
        ProtocolDataUnit pdu = TargetPduFactory.createDataInPdu(true,// finalFlag
            false,// acknowledgeFlag always false
            residualOverflow,// residualOverflowFlag x
            residualUnderflow,// residualUnderflowFlag x
            true,// statusFlag
            SCSIStatus.GOOD,// status, reserved
View Full Code Here

    public void execute (ProtocolDataUnit pdu) throws IOException , InterruptedException , InternetSCSIException , DigestException , SettingsException {

        final BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();
        final SCSICommandParser parser = (SCSICommandParser) bhs.getParser();

        ProtocolDataUnit responsePdu = null;// the response PDU

        // get command details in CDB
        if (LOGGER.isDebugEnabled()) {// print CDB bytes
            LOGGER.debug("CDB bytes: \n" + Debug.byteBufferToString(parser.getCDB()));
        }
View Full Code Here

TOP

Related Classes of org.jscsi.parser.ProtocolDataUnit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.