Example #1
0
        private T ParseResponse <T>(ProtocolDataUnit pdu)
            where T : BaseResponse, new()
        {
            BaseResponse resp;

            switch (pdu.OpCode)
            {
            case OpCode.LoginResponse:
                resp = new LoginResponse();
                break;

            case OpCode.LogoutResponse:
                resp = new LogoutResponse();
                break;

            case OpCode.ReadyToTransfer:
                resp = new ReadyToTransferPacket();
                break;

            case OpCode.Reject:
                resp = new RejectPacket();
                break;

            case OpCode.ScsiDataIn:
                resp = new DataInPacket();
                break;

            case OpCode.ScsiResponse:
                resp = new Response();
                break;

            case OpCode.TextResponse:
                resp = new TextResponse();
                break;

            default:
                throw new InvalidProtocolException("Unrecognized response opcode: " + pdu.OpCode);
            }

            resp.Parse(pdu);
            if (resp.StatusPresent)
            {
                SeenStatusSequenceNumber(resp.StatusSequenceNumber);
            }

            T result = resp as T;

            if (result == null)
            {
                throw new InvalidProtocolException("Unexpected response, expected " + typeof(T) + ", got " + result.GetType());
            }

            return(result);
        }
Example #2
0
        private ProtocolDataUnit ReadPdu()
        {
            ProtocolDataUnit pdu = ProtocolDataUnit.ReadFrom(_stream, HeaderDigest != Digest.None, DataDigest != Digest.None);

            if (pdu.OpCode == OpCode.Reject)
            {
                RejectPacket pkt = new RejectPacket();
                pkt.Parse(pdu);

                throw new IscsiException("Target sent reject packet, reason " + pkt.Reason);
            }

            return(pdu);
        }