Examples of InitiatorMessageParser


Examples of org.jscsi.parser.InitiatorMessageParser

            @Override
            public ProtocolDataUnit check (final Connection pConnection) throws InterruptedException , IOException , InternetSCSIException {
                ProtocolDataUnit responsePdu;
                final BasicHeaderSegment bhs = new ProtocolDataUnitFactory().create(false, true, OperationCode.SCSI_TM_REQUEST, "None", "None").getBasicHeaderSegment();
                final InitiatorMessageParser parser = (InitiatorMessageParser) bhs.getParser();

                final FieldPointerSenseKeySpecificData fp = new FieldPointerSenseKeySpecificData(true,// senseKeySpecificDataValid
                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 };

                // create the whole sense data
                FixedFormatSenseData senseData = new FixedFormatSenseData(false,// valid
                ErrorType.CURRENT,// error type
                false,// file mark
                false,// end of medium
                false,// incorrect length indicator
                SenseKey.ILLEGAL_REQUEST,// sense key
                new FourByteInformation(),// information
                new FourByteInformation(),// command specific information
                AdditionalSenseCodeAndQualifier.INVALID_FIELD_IN_CDB,// additional sense
                                                                     // code and
                // qualifier
                (byte) 0,// field replaceable unit code
                fpArray[0],// sense key specific data, only report
                           // first problem
                new AdditionalSenseBytes());// additional sense bytes

                // keep only the part of the sense data that will be sent
                final ScsiResponseDataSegment dataSegment = new ScsiResponseDataSegment(senseData, parser.getExpectedStatusSequenceNumber());
                final int senseDataSize = senseData.size();

                // calculate residuals and flags
                final int residualCount = Math.abs(parser.getExpectedStatusSequenceNumber() - senseDataSize);
                final boolean residualOverflow = parser.getExpectedStatusSequenceNumber() < senseDataSize;
                final boolean residualUnderflow = parser.getExpectedStatusSequenceNumber() > senseDataSize;

                // create and return PDU
                responsePdu = TargetPduFactory.createSCSIResponsePdu(false,// bidirectionalReadResidualOverflow
                        false,// bidirectionalReadResidualUnderflow
                        residualOverflow,// residualOverflow
                        residualUnderflow,// residualUnderflow,
                        SCSIResponseParser.ServiceResponse.COMMAND_COMPLETED_AT_TARGET,// response,
                        SCSIStatus.CHECK_CONDITION,// status,
                        bhs.getInitiatorTaskTag(),// initiatorTaskTag,
                        0,// snackTag
                        0,// expectedDataSequenceNumber
                        0,// bidirectionalReadResidualCount
                        residualCount,// residualCount
                        dataSegment);// data segment

                return responsePdu;
            }
        }, // FormatUnitStage checker
        new Checker() {

            @Override
            public ProtocolDataUnit check (final Connection pConnection) throws InterruptedException , IOException , InternetSCSIException {
                ProtocolDataUnit responsePdu;
                final BasicHeaderSegment bhs = new ProtocolDataUnitFactory().create(false, true, OperationCode.SCSI_COMMAND, "None", "None").getBasicHeaderSegment();
                final SCSICommandParser parser = (SCSICommandParser) bhs.getParser();

                // Taken from the stage
                final int residualCount = Math.abs(parser.getExpectedDataTransferLength() - 0);
                final boolean residualOverflow = parser.getExpectedDataTransferLength() < 0;
                final boolean residualUnderflow = parser.getExpectedDataTransferLength() > 0;

                responsePdu = TargetPduFactory.createSCSIResponsePdu(false,// bidirectionalReadResidualOverflow
                        false,// bidirectionalReadResidualUnderflow
                        residualOverflow,// residualOverflow,
                        residualUnderflow,// residualUnderflow,
View Full Code Here

Examples of org.jscsi.parser.InitiatorMessageParser

    public final void sendOverWire (final ProtocolDataUnit unit) throws InternetSCSIException , IOException , InterruptedException {

        final Session session = connection.getSession();

        unit.getBasicHeaderSegment().setInitiatorTaskTag(session.getInitiatorTaskTag());
        final InitiatorMessageParser parser = (InitiatorMessageParser) unit.getBasicHeaderSegment().getParser();
        parser.setCommandSequenceNumber(session.getCommandSequenceNumber());
        parser.setExpectedStatusSequenceNumber(connection.getExpectedStatusSequenceNumber().getValue());

        unit.write(socketChannel);

        LOGGER.debug("Sending this PDU: " + unit);

        // increment the Command Sequence Number
        if (parser.incrementSequenceNumber()) {
            connection.getSession().incrementCommandSequenceNumber();
        }

    }
View Full Code Here

Examples of org.jscsi.parser.InitiatorMessageParser

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

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

        // the SCSI OpCode is not supported, tell the initiator

        final FieldPointerSenseKeySpecificData fp = new FieldPointerSenseKeySpecificData(true,// senseKeySpecificDataValid
        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 };

        // If the parser is null..
        int essn = -1;

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

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

Examples of org.jscsi.parser.InitiatorMessageParser

        if (LOGGER.isDebugEnabled()) LOGGER.debug("Receiving this PDU:\n" + pdu);

        // parse sequence counters
        final BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();
        final InitiatorMessageParser parser = (InitiatorMessageParser) bhs.getParser();
        // final int commandSequenceNumber = parser.getCommandSequenceNumber();
        // final int expectedStatusSequenceNumber = parser.getExpectedStatusSequenceNumber();

        if (LOGGER.isDebugEnabled()) {
            // sharrajesh
            // Needed to debug, out of order receiving of StatusSN and ExpStatSN
            if (bhs.getOpCode() == OperationCode.SCSI_COMMAND) {
                final SCSICommandParser scsiParser = (SCSICommandParser) bhs.getParser();
                ScsiOperationCode scsiOpCode = ScsiOperationCode.valueOf(scsiParser.getCDB().get(0));
                LOGGER.debug("scsiOpCode = " + scsiOpCode);
                LOGGER.debug("CDB bytes: \n" + Debug.byteBufferToString(scsiParser.getCDB()));
            }
            // LOGGER.debug("parser.expectedStatusSequenceNumber: " + expectedStatusSequenceNumber);
            if (connection == null)
                LOGGER.debug("connection: null");
            else if (connection.getStatusSequenceNumber() == null)
                LOGGER.debug("connection.getStatusSequenceNumber: null");
            else
                LOGGER.debug("connection.getStatusSequenceNumber: " + connection.getStatusSequenceNumber().getValue());
        }

        // if this is the first PDU in the leading connection, then
        // initialize the session's ExpectedCommandSequenceNumber
        if (initialPdu) {
            initialPdu = false;
            // PDU is immediate Login PDU, checked in Target.main(),
            // ExpCmdSN of this PDU will be used to initialize the
            // respective session and connection parameters (sequence numbers)
            // see TargetSession and TargetConnection initialization in
            // Target.main()
        } else {
            // check sequence counters
            // if (session.getMaximumCommandSequenceNumber().lessThan(commandSequenceNumber))
            // throw new InternetSCSIException("received CmdSN > local MaxCmdSN");

            // verified, is working with Windows 8 initiator
            // if (!connection.getStatusSequenceNumber().equals(expectedStatusSequenceNumber)
            // && expectedStatusSequenceNumber != 0)// required by MS iSCSI
            // // initiator DATA-OUT
            // // PDU sequence
            // throw new InternetSCSIException("received ExpStatusSN != local StatusSN + 1");
        }

        // increment CmdSN if not immediate PDU (or Data-Out PDU)
        try {
            if (parser.incrementSequenceNumber()) session.getExpectedCommandSequenceNumber().increment();
        } catch (NullPointerException exc) {

        }

        return pdu;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.