Package org.jscsi.parser.data

Examples of org.jscsi.parser.data.DataOutParser


            case TEXT_REQUEST :
                return new TextRequestParser(protocolDataUnit);
            case TEXT_RESPONSE :
                return new TextResponseParser(protocolDataUnit);
            case SCSI_DATA_OUT :
                return new DataOutParser(protocolDataUnit);
            case SCSI_DATA_IN :
                return new DataInParser(protocolDataUnit);
            case NOP_OUT :
                return new NOPOutParser(protocolDataUnit);
            case NOP_IN :
View Full Code Here


    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);
View Full Code Here

     *            {@link BasicHeaderSegment}
     * @throws InternetSCSIException if an unexpected PDU has been received
     */
    private void checkDataOutParser (final AbstractMessageParser parser) throws InternetSCSIException {
        if (parser instanceof DataOutParser) {
            final DataOutParser p = (DataOutParser) parser;
            if (p.getDataSequenceNumber() != expectedDataSequenceNumber++) { throw new InternetSCSIException("received erroneous PDU in data-out sequence, expected " + (expectedDataSequenceNumber - 1)); }
        } else if (parser instanceof NOPOutParser || parser instanceof SCSICommandParser) {

        } else {
            if (parser != null) {
                throw new InternetSCSIException("received erroneous PDU in data-out sequence, " + parser.getClass().getName());
View Full Code Here

                pdu = connection.receivePdu();
                bhs = pdu.getBasicHeaderSegment();

                checkDataOutParser(bhs.getParser());

                final DataOutParser dataOutParser = (DataOutParser) bhs.getParser();

                session.getStorageModule().write(pdu.getDataSegment().array(), storageIndex + dataOutParser.getBufferOffset());
                ;
                bytesReceived += bhs.getDataSegmentLength();

                if (bhs.isFinalFlag()) firstBurstOver = true;
            }
        }

        // *** receive solicited data ***
        if (bytesReceived < transferLengthInBytes) {
            if (LOGGER.isDebugEnabled()) LOGGER.debug(bytesReceived + "<" + transferLengthInBytes);

            int readyToTransferSequenceNumber = 0;
            int desiredDataTransferLength;

            while (bytesReceived < transferLengthInBytes) {

                desiredDataTransferLength = Math.min(maxBurstLength, transferLengthInBytes - bytesReceived);

                // send R2T
                pdu = TargetPduFactory.createReadyToTransferPdu(0,// logicalUnitNumber
                        initiatorTaskTag, TargetServer.getNextTargetTransferTag(),// targetTransferTag
                        readyToTransferSequenceNumber++, bytesReceived,// bufferOffset
                        desiredDataTransferLength);

                connection.sendPdu(pdu);

                // receive DataOut PDUs
                expectedDataSequenceNumber = 0;// reset sequence counter//FIXME
                                               // fix in jSCSI Initiator
                boolean solicitedDataCycleOver = false;
                int bytesReceivedThisCycle = 0;
                while (!solicitedDataCycleOver) {

                    // receive and check PDU
                    pdu = connection.receivePdu();
                    bhs = pdu.getBasicHeaderSegment();
                    checkDataOutParser(bhs.getParser());

                    if (bhs.getParser() instanceof NOPOutParser) {

                        /* send SCSI Response PDU */
                        pdu = TargetPduFactory.createSCSIResponsePdu(false,// bidirectionalReadResidualOverflow
                                false,// bidirectionalReadResidualUnderflow
                                false,// residualOverflow
                                false,// residualUnderflow
                                SCSIResponseParser.ServiceResponse.COMMAND_COMPLETED_AT_TARGET,// response
                                SCSIStatus.GOOD,// status
                                initiatorTaskTag, 0,// snackTag
                                0,// (ExpDataSN or) Reserved
                                0,// bidirectionalReadResidualCount
                                0,// residualCount
                                ScsiResponseDataSegment.EMPTY_DATA_SEGMENT);// dataSegment

                        connection.sendPdu(pdu);
                        return;
                    } else if (bhs.getParser() instanceof DataOutParser) {
                        final DataOutParser dataOutParser = (DataOutParser) bhs.getParser();

                        session.getStorageModule().write(pdu.getDataSegment().array(), storageIndex + dataOutParser.getBufferOffset());

                        bytesReceivedThisCycle += bhs.getDataSegmentLength();

                        /*
                         * Checking the final flag should be enough, but is not, when dealing with the jSCSI Initiator.
View Full Code Here

    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);
        int bytes2Transfer = Math.min(connection.getSettingAsInt(OperationalTextKey.MAX_BURST_LENGTH), desiredDataTransferLength);

        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("bytes2Transfer: " + bytes2Transfer + " iterator.hasNext(): " + iterator.hasNext());
        }

        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);
View Full Code Here

TOP

Related Classes of org.jscsi.parser.data.DataOutParser

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.