Package org.jscsi.target.settings

Examples of org.jscsi.target.settings.ConnectionSettingsNegotiator


        final ProtocolDataUnit textNegotationUnit = new ProtocolDataUnitFactory().create(false, true, OperationCode.SCSI_TM_REQUEST, "None", "None");
        textNegotationUnit.setDataSegment(ByteBuffer.wrap("hello world".getBytes()));

        // setting up the connection properly
        SessionSettingsNegotiator sessionSettingsNegotiator = new SessionSettingsNegotiator();
        ConnectionSettingsNegotiator connectionSettingsNegotiator = new ConnectionSettingsNegotiator(sessionSettingsNegotiator);
        final TargetSession session = mock(TargetSession.class);

        when(connection.getSettings()).thenReturn(connectionSettingsNegotiator.getSettings());

        // setting up the phases
        TargetFullFeaturePhase phase = new TargetFullFeaturePhase(connection);
        Object[][] returnVal = { { TargetStage.class, new TargetStage[] { new TestUnitReadyStage(phase), new SendDiagnosticStage(phase), new ReportLunsStage(phase), new InquiryStage(phase), new RequestSenseStage(phase), new TextNegotiationStage(phase), new UnsupportedOpCodeStage(phase), new FormatUnitStage(phase) }, ProtocolDataUnit.class, new ProtocolDataUnit[] {
                // TextUnitReadyStage
View Full Code Here


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

        // begin login negotiation
        final ConnectionSettingsNegotiator negotiator = connection.getConnectionSettingsNegotiator();
        while (!negotiator.beginNegotiation()) {
            // do nothing, just wait for permission to begin, method is blocking
        }

        boolean loginSuccessful = true;// will determine if settings are
                                       // committed

        try {
            // if possible, enter LOPN Stage
            BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();
            LoginRequestParser parser = (LoginRequestParser) bhs.getParser();

            LoginStage nextStageNumber;// will store return value from the last
                                       // login stage

            // Security Negotiation Stage (optional)
            if (parser.getCurrentStageNumber() == LoginStage.SECURITY_NEGOTIATION) {
                // complete SNS
                stage = new SecurityNegotiationStage(this);
                stage.execute(pdu);
                nextStageNumber = stage.getNextStageNumber();

                if (nextStageNumber != null)
                    authenticated = true;
                else {
                    loginSuccessful = false;
                    return false;
                }

                if (nextStageNumber == LoginStage.LOGIN_OPERATIONAL_NEGOTIATION) {
                    // receive first PDU from LOPNS
                    pdu = connection.receivePdu();
                    bhs = pdu.getBasicHeaderSegment();
                    parser = (LoginRequestParser) bhs.getParser();
                } else if (nextStageNumber == LoginStage.FULL_FEATURE_PHASE) {
                    // we are done here
                    return true;
                } else {
                    // should be unreachable, since SNS may not return NSG==SNS
                    loginSuccessful = false;
                    return false;
                }
            }

            // Login Operational Parameter Negotiation Stage (also optional, but
            // either SNS or LOPNS must be passed before proceeding to FFP)
            if (parser != null && authenticated && parser.getCurrentStageNumber() == LoginStage.LOGIN_OPERATIONAL_NEGOTIATION) {
                stage = new LoginOperationalParameterNegotiationStage(this);
                stage.execute(pdu);
                nextStageNumber = stage.getNextStageNumber();
                if (nextStageNumber == LoginStage.FULL_FEATURE_PHASE) return true;
            }
            // else
            loginSuccessful = false;
            return false;
        } catch (DigestException e) {
            loginSuccessful = false;
            throw e;
        } catch (IOException e) {
            loginSuccessful = false;
            throw e;
        } catch (InterruptedException e) {
            loginSuccessful = false;
            throw e;
        } catch (InternetSCSIException e) {
            loginSuccessful = false;
            throw e;
        } catch (SettingsException e) {
            loginSuccessful = false;
            throw e;
        } finally {
            // commit or roll back changes and release exclusive negotiator lock
            negotiator.finishNegotiation(loginSuccessful);
        }
    }
View Full Code Here

         * Initializes {@link #connectionSettingsNegotiator}.
         * <p>
         * This method must be be called after the this connection has been added to its session.
         */
        public void initializeConnectionSettingsNegotiator (final SessionSettingsNegotiator sessionSettingsNegotiator) {
            connectionSettingsNegotiator = new ConnectionSettingsNegotiator(sessionSettingsNegotiator);
        }
View Full Code Here

TOP

Related Classes of org.jscsi.target.settings.ConnectionSettingsNegotiator

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.