Package org.jscsi.parser

Examples of org.jscsi.parser.ProtocolDataUnit


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

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

        final ProtocolDataUnit protocolDataUnit = protocolDataUnitFactory.create(true, true, OperationCode.LOGOUT_REQUEST, connection.getSetting(OperationalTextKey.HEADER_DIGEST), connection.getSetting(OperationalTextKey.DATA_DIGEST));
        final LogoutRequestParser logoutRequest = (LogoutRequestParser) protocolDataUnit.getBasicHeaderSegment().getParser();

        logoutRequest.setReasonCode(reasonCode);
        if (reasonCode != LogoutReasonCode.CLOSE_SESSION) {
            logoutRequest.setConnectionID(connection.getConnectionID());
        }
View Full Code Here


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

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

        final ProtocolDataUnit protocolDataUnit = connection.receive();

        // first, we extract capacity informations
        if (!(protocolDataUnit.getBasicHeaderSegment().getParser() instanceof DataInParser)) {

            // In newer versions of iscsi targets there the target tells the initiator
            // that the status is cleared using a scsi response. It's defined in the RFC 3720 on page 78 (or
            // at least mentioned, it's
            // actually defined in SAM-2 and). This is why we have to ask for capacity informations once again
            // receiving this
            // Response to our capacity request.
            if (protocolDataUnit.getBasicHeaderSegment().getParser() instanceof SCSIResponseParser) {
                connection.nextState(new CapacityRequestState(connection, capacityInformation, TaskAttributes.SIMPLE));
                super.stateFollowing = true;
                return;
            } else {
                throw new InternetSCSIException(protocolDataUnit.getBasicHeaderSegment().getParser().getClass().getSimpleName() + " is not the expected type of PDU.");
            }
        }

        /**
         * The server responded using the data-in-parser.
         */
        final DataInParser parser = (DataInParser) protocolDataUnit.getBasicHeaderSegment().getParser();

        capacityInformation.deserialize(protocolDataUnit.getDataSegment());

        if (!parser.isStatusFlag() || parser.getStatus() != SCSIStatus.GOOD) {
            // receive SCSI Response PDU and check status (no phase
            // collapse)
            final ProtocolDataUnit scsiPdu = connection.receive();
            if (scsiPdu.getBasicHeaderSegment().getOpCode() == OperationCode.SCSI_RESPONSE) {
                final SCSIResponseParser scsiParser = (SCSIResponseParser) scsiPdu.getBasicHeaderSegment().getParser();
                if (scsiParser.getStatus() == SCSIStatus.GOOD) return;// done
            }
            throw new InternetSCSIException("Error: Task did not finish successfully.");
        }

View Full Code Here

        if (parser != null) {
            essn = parser.getExpectedStatusSequenceNumber();
        }

        final ProtocolDataUnit responsePdu = createFixedFormatErrorPdu(fpArray,// senseKeySpecificData
                bhs.getInitiatorTaskTag(),// initiatorTaskTag
                essn);// expectedDataTransferLength

        // send response
        connection.sendPdu(responsePdu);
View Full Code Here

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

        final Queue<ProtocolDataUnit> protocolDataUnits = new LinkedList<ProtocolDataUnit>();

        ProtocolDataUnit protocolDataUnit;
        DataOutParser dataOut;
        IDataSegmentChunk dataSegmentChunk;
        boolean finalFlag = false;
        final int maxRecvDataSegmentLength = connection.getSettingAsInt(OperationalTextKey.MAX_RECV_DATA_SEGMENT_LENGTH);
        // the remaining bytes to send (do not forget the immediately send
        // data!)
        int bytes2Transfer = connection.getSettingAsInt(OperationalTextKey.FIRST_BURST_LENGTH) - bufferOffset;

        while (bytes2Transfer > 0 && iterator.hasNext()) {
            if (bytes2Transfer <= maxRecvDataSegmentLength) {
                dataSegmentChunk = iterator.next(bytes2Transfer);
                finalFlag = true;
            } else {
                dataSegmentChunk = iterator.next(maxRecvDataSegmentLength);
                finalFlag = false;
            }

            protocolDataUnit = protocolDataUnitFactory.create(false, finalFlag, OperationCode.SCSI_DATA_OUT, connection.getSetting(OperationalTextKey.HEADER_DIGEST), connection.getSetting(OperationalTextKey.DATA_DIGEST));
            protocolDataUnit.getBasicHeaderSegment().setInitiatorTaskTag(connection.getSession().getInitiatorTaskTag());

            dataOut = (DataOutParser) protocolDataUnit.getBasicHeaderSegment().getParser();

            dataOut.setTargetTransferTag(targetTransferTag);
            dataOut.setDataSequenceNumber(dataSequenceNumber++);
            dataOut.setBufferOffset(bufferOffset);
            bufferOffset += maxRecvDataSegmentLength;

            protocolDataUnit.setDataSegment(dataSegmentChunk);

            protocolDataUnits.offer(protocolDataUnit);
            bytes2Transfer -= maxRecvDataSegmentLength;
        }

View Full Code Here

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

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

        ProtocolDataUnit protocolDataUnit;

        do {
            protocolDataUnit = connection.receive();
            boolean dataWasRead = false;
            if (protocolDataUnit.getBasicHeaderSegment().getParser() instanceof DataInParser) {
                final DataInParser parser = (DataInParser) protocolDataUnit.getBasicHeaderSegment().getParser();

                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Remaining, DataSegmentLength: " + buffer.remaining() + ", " + protocolDataUnit.getBasicHeaderSegment().getDataSegmentLength());
                }

                final ByteBuffer dataSegment = protocolDataUnit.getDataSegment();
                while (buffer.hasRemaining() && dataSegment.hasRemaining()) {
                    buffer.put(dataSegment.get());
                }
                dataWasRead = true;
                // last message with the status flag set
                if (parser.isStatusFlag() && parser.getStatus() == SCSIStatus.GOOD) {
                    // return false;
                    return;
                } else if (connection.getSettingAsInt(OperationalTextKey.ERROR_RECOVERY_LEVEL) > 0 && parser.isAcknowledgeFlag()) {
                    // TODO: Test this case
                    // send a DataAck
                    connection.nextState(new SNACKRequestState(connection, this, parser.getTargetTaskTag()));
                    // return true;
                    return;
                } else if (protocolDataUnit.getBasicHeaderSegment().getParser() instanceof SCSIResponseParser && !dataWasRead) {
                    readHandleImmediateData(protocolDataUnit);
                }
            }
        } while (!protocolDataUnit.getBasicHeaderSegment().isFinalFlag());

        if (connection.getSettingAsBoolean(OperationalTextKey.IMMEDIATE_DATA)) {
            return;
        } else {
            protocolDataUnit = connection.receive();
            if (protocolDataUnit.getBasicHeaderSegment().getParser() instanceof SCSIResponseParser) {
                readHandleImmediateData(protocolDataUnit);
            }
        }

    }
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
        final SendDiagnosticCdb cdb = new SendDiagnosticCdb(parser.getCDB());
        final FieldPointerSenseKeySpecificData[] illegalFieldPointers = cdb.getIllegalFieldPointers();
View Full Code Here

        final IDataSegment dataSegment = DataSegmentFactory.create(loginParameters.asByteBuffer(), DataSegmentFormat.TEXT, maxRecvDataSegmentLength);
        final IDataSegmentIterator iterator = dataSegment.iterator();
        final Queue<ProtocolDataUnit> protocolDataUnits = new LinkedList<ProtocolDataUnit>();

        IDataSegmentChunk dataSegmentChunk;
        ProtocolDataUnit protocolDataUnit;
        int bytes2Transfer = dataSegment.getLength();

        while (bytes2Transfer > 0 && iterator.hasNext()) {

            if (bytes2Transfer <= maxRecvDataSegmentLength) {
                // last PDU to send...
                dataSegmentChunk = iterator.next(bytes2Transfer);
                continueFlag = false;
            } else {
                dataSegmentChunk = iterator.next(maxRecvDataSegmentLength);
                continueFlag = true;
            }

            finalFlag = !continueFlag;
            protocolDataUnit = protocolDataUnitFactory.create(true, finalFlag, OperationCode.LOGIN_REQUEST, "None", "None");
            loginRequest = (LoginRequestParser) protocolDataUnit.getBasicHeaderSegment().getParser();

            loginRequest.setContinueFlag(continueFlag);
            loginRequest.setCurrentStageNumber(connection.getSession().getPhase());
            LOGGER.debug("Phase:\n" + loginRequest.getCurrentStageNumber());
            if (finalFlag) {
                loginRequest.setNextStageNumber(nextStage);
            }
            loginRequest.setMaxVersion(MAXIMUM_VERSION);
            loginRequest.setMinVersion(MINIMUM_VERSION);

            loginRequest.setInitiatorSessionID(isid);
            loginRequest.setTargetSessionIdentifyingHandle(connection.getSession().getTargetSessionIdentifyingHandle());

            protocolDataUnit.setDataSegment(dataSegmentChunk);

            protocolDataUnits.offer(protocolDataUnit);
            bytes2Transfer -= maxRecvDataSegmentLength;
        }
View Full Code Here

            LOGGER.debug("CDB:\n" + Debug.byteBufferToString(parser.getCDB()));
           
            // Not necessarily close the connection

            // create and send error PDU and leave stage
            final ProtocolDataUnit responsePdu = createFixedFormatErrorPdu(cdb.getIllegalFieldPointers(),// senseKeySpecificData
                    initiatorTaskTag, parser.getExpectedDataTransferLength());
            connection.sendPdu(responsePdu);
            return;
        }
View Full Code Here

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

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

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

        do {
            protocolDataUnit = connection.receive();

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

            textResponse.append(protocolDataUnit.getDataSegment(), protocolDataUnit.getBasicHeaderSegment().getDataSegmentLength());
        } while (!protocolDataUnit.getBasicHeaderSegment().isFinalFlag());

        // extract Target Session Handle Identifying Handle
        // final TextResponseParser parser = (TextResponseParser)
        // protocolDataUnit.getBasicHeaderSegment().getParser();
        // final ByteBuffer textDataSegment = ByteBuffer
View Full Code Here

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

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

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

        final SNACKRequestParser parser = (SNACKRequestParser) protocolDataUnit.getBasicHeaderSegment().getParser();
        parser.setType(SNACKType.DATA_ACK);
        parser.setTargetTransferTag(targetTransferTag);

        connection.send(protocolDataUnit);
        connection.nextState(prevState);
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.