All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jscsi.parser.nop.NOPInParser Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (c) 2012, University of Konstanz, Distributed Systems Group All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
 * following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of
 * conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation and/or other materials provided with the
 * distribution. * Neither the name of the University of Konstanz nor the names of its contributors may be used to
 * endorse or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package org.jscsi.parser.nop;


import org.jscsi.exception.InternetSCSIException;
import org.jscsi.parser.Constants;
import org.jscsi.parser.ProtocolDataUnit;
import org.jscsi.parser.TargetMessageParser;
import org.jscsi.parser.datasegment.DataSegmentFactory.DataSegmentFormat;
import org.jscsi.utils.Utils;


/**
 * 

NOPInParser

*

* This class parses a NOP-In message defined in the iSCSI Standard (RFC3720). *

* NOP-In is either sent by a target as a response to a NOP-Out, as a "ping" to an initiator, or as a means to carry a * changed ExpCmdSN and/or MaxCmdSN if another PDU will not be available for a long time (as * determined by the target). *

* When a target receives the NOP-Out with a valid Initiator Task Tag (not the reserved value 0xffffffff), * it MUST respond with a NOP-In with the same Initiator Task Tag that was provided in the NOP-Out request. It MUST also * duplicate up to the first MaxRecvDataSegmentLength bytes of the initiator provided Ping Data. For such a * response, the Target Transfer Tag MUST be 0xffffffff. *

* Otherwise, when a target sends a NOP-In that is not a response to a Nop-Out received from the initiator, the * Initiator Task Tag MUST be set to 0xffffffff and the Data Segment MUST NOT contain any data * (DataSegmentLength MUST be 0). *

* This fields have these specific meanings: *

* A LUN MUST be set to a correct value when the Target Transfer Tag is valid (not the reserved value * 0xffffffff). *

* The StatSN field will always contain the next StatSN. However, when the Initiator Task Tag is set to * 0xffffffff, StatSN for the connection is not advanced after this PDU is sent. *

* * @author Volker Wildi */ public final class NOPInParser extends TargetMessageParser { // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- /** Target Transfer Tag. */ private int targetTransferTag; // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- /** * Default constructor, creates a new, empty NOPInParser object. * * @param initProtocolDataUnit The reference ProtocolDataUnit instance, which contains this * NOPInParser subclass object. */ public NOPInParser (final ProtocolDataUnit initProtocolDataUnit) { super(initProtocolDataUnit); } // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- /** * If the target is responding to a NOP-Out, this is set to the reserved value 0xffffffff. *

* If the target is sending a NOP-In as a Ping (intending to receive a corresponding NOP-Out), this field is set to * a valid value (not the reserved 0xffffffff). *

* If the target is initiating a NOP-In without wanting to receive a corresponding NOP-Out, this field MUST hold the * reserved value of 0xffffffff. * * @return The target transfer tag of this object. */ public final int getTargetTransferTag () { return targetTransferTag; } /** * Sets the Target Transfer Tag of this object. * * @param targetTransferTag the new Target Transfer Tag. */ public final void setTargetTransferTag (final int targetTransferTag) { this.targetTransferTag = targetTransferTag; } // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- /** {@inheritDoc} */ @Override public final String toString () { final StringBuilder sb = new StringBuilder(Constants.LOG_INITIAL_SIZE); Utils.printField(sb, "LUN", logicalUnitNumber, 1); Utils.printField(sb, "Target Transfer Tag", targetTransferTag, 1); sb.append(super.toString()); return sb.toString(); } /** {@inheritDoc} */ @Override public final DataSegmentFormat getDataSegmentFormat () { return DataSegmentFormat.BINARY; } /** {@inheritDoc} */ @Override public final void clear () { super.clear(); targetTransferTag = 0x00000000; } // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- /** {@inheritDoc} */ @Override protected final void deserializeBytes1to3 (final int line) throws InternetSCSIException { Utils.isReserved(line & Constants.LAST_THREE_BYTES_MASK); } /** {@inheritDoc} */ @Override protected final void deserializeBytes20to23 (final int line) throws InternetSCSIException { targetTransferTag = line; } // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- /** {@inheritDoc} */ @Override protected final void checkIntegrity () throws InternetSCSIException { // do nothing... } // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- /** {@inheritDoc} */ @Override protected final int serializeBytes20to23 () { return targetTransferTag; } // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy