The SMBDirect Negotiate Response message is the second message sent on a new SMBDirect connection, in response to the SMBDirect Negotiate Request message, to complete the establishment of an SMBDirect connection.
        public void BasicNegotiate(
            ushort creditsRequested,
            uint preferredSendSize,
            uint maxReceiveSize,
            uint maxFragmentedSize,
            out SmbdNegotiateResponse response)
        {
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Connect to server over RDMA");
            NtStatus status = smbdAdapter.ConnectToServerOverRDMA();
            BaseTestSite.Assert.AreEqual<NtStatus>(NtStatus.STATUS_SUCCESS, status, "Status of SMBD connection is {0}", status);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "SMBD Negotiate");
            status = smbdAdapter.SmbdNegotiate(
                creditsRequested,
                (ushort)smbdAdapter.TestConfig.ReceiveCreditMax,
                preferredSendSize,
                maxReceiveSize,
                maxFragmentedSize,
                out response,
                SmbdVersion.V1,
                SmbdVersion.V1
                );
            BaseTestSite.Assert.AreEqual<NtStatus>(NtStatus.STATUS_SUCCESS, status, "Status of SMBD negotiate is {0}", status);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Verify SMBD negotiate response");
            NegotiateBasicChecker(
                response,
                creditsRequested,
                maxReceiveSize,
                preferredSendSize,
                maxFragmentedSize);
        }
 public void NegotiateBasicChecker(
     SmbdNegotiateResponse response,
     ushort creditsRequested,
     uint maxReceiveSize,
     uint preferredSendSize,
     uint maxFragmentedSize)
 {
     // verify the response
     BaseTestSite.Assert.AreEqual<SmbdVersion>(
         SmbdVersion.V1,
         response.MinVersion,
         "MinVersion in negotiate response is {0}", response.MinVersion);
     BaseTestSite.Assert.AreEqual<SmbdVersion>(
         SmbdVersion.V1,
         response.MaxVersion,
         "MaxVersion in negotiate response is {0}", response.MaxVersion);
     BaseTestSite.Assert.AreEqual<SmbdVersion>(
         SmbdVersion.V1,
         response.NegotiatedVersion,
         "NegotiatedVersion in negotiate response is {0}", response.NegotiatedVersion);
     BaseTestSite.Assert.AreEqual<ushort>(
         0,
         response.Reserved,
         "Reserved in negotiate response is {0}", response.Reserved);
     BaseTestSite.Assert.IsTrue(
         response.CreditsGranted > 0 && response.CreditsGranted <= creditsRequested,
         "CreditsGranted in negotiate response is {0}", response.CreditsGranted);
     BaseTestSite.Assert.IsTrue(
         response.CreditsRequested > 0,
         "CreditsRequested in negotiate response is {0}", response.CreditsRequested);
     BaseTestSite.Assert.AreEqual<uint>(
         0,
         response.Status,
         "Status in negotiate response is {0}", response.Status);
     BaseTestSite.Assert.IsTrue(
         response.MaxReadWriteSize >= SmbdConnection.FLOOR_MAX_READ_WRITE_SIZE,
         "MaxReadWriteSize in negotiate response is {0}", response.MaxReadWriteSize);
     if (preferredSendSize >= SmbdConnection.FLOOR_MAX_RECEIVE_SIZE)
     {
         // sever MUST set Connection.MaxReceiveSize to the smaller(Connection.MaxReceiveSize, PreferredSendSize)
         // If the result is smaller than 128, then Connection.MaxReceiveSize MUST be set to 128.
         BaseTestSite.Assert.IsTrue(
             response.MaxReceiveSize >= SmbdConnection.FLOOR_MAX_RECEIVE_SIZE && response.MaxReceiveSize <= preferredSendSize,
             "MaxReceiveSize in negotiate response is {0}", response.MaxReceiveSize);
     }
     // server MUST set Connection.MaxSendSize to the smaller(Connection.MaxSendSize, MaxReceiveSize).
     BaseTestSite.Assert.IsTrue(
         response.PreferredSendSize >= SmbdConnection.FLOOR_MAX_RECEIVE_SIZE && response.PreferredSendSize <= maxReceiveSize,
         "PreferredSendSize in negotiate response is {0}", response.PreferredSendSize);
     BaseTestSite.Assert.IsTrue(
         response.MaxFragmentedSize >= SmbdConnection.FLOOR_MAX_FRAGMENTED_SIZE,
         "MaxFragmentedSize in negotiate response is {0}", response.MaxFragmentedSize);
 }
Beispiel #3
0
        /// <summary>
        /// SMBDirect Negotiate
        /// </summary>
        /// <param name="minVersion">The minimum SMBDirect Protocol version supported by the sender</param>
        /// <param name="maxVersion">The maximum SMBDirect Protocol version supported by the sender</param>
        /// <param name="creditsRequested">The number of Send Credits requested of the receiver</param>
        /// <param name="receiveCreditMax">Maximum of receive credits</param>
        /// <param name="preferredSendSize">The maximum number of bytes that the sender requests to transmit in a single message</param>
        /// <param name="maxReceiveSize">The maximum number of bytes that the sender can receive in a single message</param>
        /// <param name="maxFragmentedSize">The maximum number of upper-layer bytes that the sender can receive as the result of a sequence of fragmented Send operations</param>
        /// <param name="smbdNegotiateResponse">SMBDirect Negotiate response</param>
        /// <param name="reserved">The sender SHOULD set this field to 0 and the receiver MUST ignore it on receipt</param>
        /// <returns></returns>
        public NtStatus Negotiate(
            SmbdVersion minVersion,
            SmbdVersion maxVersion,
            ushort creditsRequested,
            ushort receiveCreditMax,
            uint preferredSendSize,
            uint maxReceiveSize,
            uint maxFragmentedSize,
            out SmbdNegotiateResponse smbdNegotiateResponse,
            ushort reserved = 0
            )
        {
            #region set SMBD connection

            Connection.ReceiveCreditMax  = receiveCreditMax;
            Connection.SendCreditTarget  = creditsRequested;
            Connection.MaxSendSize       = preferredSendSize;
            Connection.MaxFragmentedSize = maxFragmentedSize;
            Connection.MaxReceiveSize    = maxReceiveSize;
            #endregion

            smbdNegotiateResponse = new SmbdNegotiateResponse();

            // send negotiate message
            SmbdNegotiateRequest smbdRequest = new SmbdNegotiateRequest();
            smbdRequest.MinVersion        = minVersion;
            smbdRequest.MaxVersion        = maxVersion;
            smbdRequest.Reserved          = reserved;
            smbdRequest.CreditsRequested  = creditsRequested;
            smbdRequest.PreferredSendSize = preferredSendSize;
            smbdRequest.MaxReceiveSize    = maxReceiveSize;
            smbdRequest.MaxFragmentedSize = maxFragmentedSize;


            byte[] requestBytes = TypeMarshal.ToBytes <SmbdNegotiateRequest>(smbdRequest);

            // post receive
            NtStatus ret = Connection.Endpoint.PostReceive((uint)SmbdNegotiateResponse.SIZE);
            if (ret != NtStatus.STATUS_SUCCESS)
            {
                LogEvent(string.Format("Connection.Endpoint.PostReceive with error {0}", ret));
                return(ret);
            }

            // send message
            ret = (NtStatus)Connection.Endpoint.SendData(requestBytes);
            if (ret != NtStatus.STATUS_SUCCESS)
            {
                LogEvent(string.Format("Connection.Endpoint.SendData with error {0}", ret));
                return(ret);
            }

            byte[] responseBytes;
            try
            {
                ret = Connection.Endpoint.ReceiveData(
                    TimeSpan.FromSeconds(SmbdConnection.ACTIVE_NEGOTIATION_TIMEOUT),
                    out responseBytes);
                if (ret != NtStatus.STATUS_SUCCESS)
                {
                    LogEvent(string.Format("Connection.Endpoint.ReceiveData with error {0}", ret));
                    return(ret);
                }
            }
            catch (TimeoutException e)
            {
                LogEvent(string.Format("Do not get the SMBD negotiate response within {0} seconds", SmbdConnection.ACTIVE_NEGOTIATION_TIMEOUT));
                throw new TimeoutException(e.Message);
            }

            smbdNegotiateResponse = TypeMarshal.ToStruct <SmbdNegotiateResponse>(responseBytes);
            if ((NtStatus)smbdNegotiateResponse.Status != NtStatus.STATUS_SUCCESS)
            {
                LogEvent(string.Format("SMBDirect Negotiate response with status {0}", (NtStatus)smbdNegotiateResponse.Status));
                return((NtStatus)smbdNegotiateResponse.Status);
            }

            #region set connection parameters
            Connection.Protocol            = SmbdVersion.V1;
            Connection.ReceiveCreditTarget = smbdNegotiateResponse.CreditsRequested;
            Connection.MaxReceiveSize      = Smaller(Connection.MaxReceiveSize, smbdNegotiateResponse.PreferredSendSize);
            Connection.MaxSendSize         = Smaller(Connection.MaxSendSize, smbdNegotiateResponse.MaxReceiveSize);
            Connection.MaxReadWriteSize    = Smaller(smbdNegotiateResponse.MaxReadWriteSize, SmbdConnection.FLOOR_MAX_READ_WRITE_SIZE);
            Connection.SendCredits         = smbdNegotiateResponse.CreditsGranted;
            #endregion

            Connection.Role = SmbdRole.ESTABLISHED;
            try
            {
                Connection.FragmentReassemblyBuffer = new byte[Connection.MaxFragmentedSize];
            }
            catch (OverflowException)
            {
                Connection.MaxFragmentedSize        = smbdNegotiateResponse.MaxFragmentedSize;
                Connection.FragmentReassemblyBuffer = new byte[Connection.MaxFragmentedSize];
            }
            return((NtStatus)smbdNegotiateResponse.Status);
        }
        /// <summary>
        /// SMBDirect Negotiate
        /// </summary>
        /// <param name="minVersion">The minimum SMBDirect Protocol version supported by the sender</param>
        /// <param name="maxVersion">The maximum SMBDirect Protocol version supported by the sender</param>
        /// <param name="creditsRequested">The number of Send Credits requested of the receiver</param>
        /// <param name="receiveCreditMax">Maximum of receive credits</param>
        /// <param name="preferredSendSize">The maximum number of bytes that the sender requests to transmit in a single message</param>
        /// <param name="maxReceiveSize">The maximum number of bytes that the sender can receive in a single message</param>
        /// <param name="maxFragmentedSize">The maximum number of upper-layer bytes that the sender can receive as the result of a sequence of fragmented Send operations</param>
        /// <param name="smbdNegotiateResponse">SMBDirect Negotiate response</param>
        /// <param name="reserved">The sender SHOULD set this field to 0 and the receiver MUST ignore it on receipt</param>
        /// <returns></returns>
        public NtStatus Negotiate(
            SmbdVersion minVersion,
            SmbdVersion maxVersion,
            ushort creditsRequested,
            ushort receiveCreditMax,
            uint preferredSendSize,
            uint maxReceiveSize,
            uint maxFragmentedSize,
            out SmbdNegotiateResponse smbdNegotiateResponse,
            ushort reserved = 0
            )
        {
            #region set SMBD connection

            Connection.ReceiveCreditMax = receiveCreditMax;
            Connection.SendCreditTarget = creditsRequested;
            Connection.MaxSendSize = preferredSendSize;
            Connection.MaxFragmentedSize = maxFragmentedSize;
            Connection.MaxReceiveSize = maxReceiveSize;
            #endregion

            smbdNegotiateResponse = new SmbdNegotiateResponse();

            // send negotiate message
            SmbdNegotiateRequest smbdRequest = new SmbdNegotiateRequest();
            smbdRequest.MinVersion = minVersion;
            smbdRequest.MaxVersion = maxVersion;
            smbdRequest.Reserved = reserved;
            smbdRequest.CreditsRequested = creditsRequested;
            smbdRequest.PreferredSendSize = preferredSendSize;
            smbdRequest.MaxReceiveSize = maxReceiveSize;
            smbdRequest.MaxFragmentedSize = maxFragmentedSize;

            byte[] requestBytes = TypeMarshal.ToBytes<SmbdNegotiateRequest>(smbdRequest);

            // post receive
            NtStatus ret = Connection.Endpoint.PostReceive((uint)SmbdNegotiateResponse.SIZE);
            if (ret != NtStatus.STATUS_SUCCESS)
            {
                LogEvent(string.Format("Connection.Endpoint.PostReceive with error {0}", ret));
                return ret;
            }

            // send message
            ret = (NtStatus)Connection.Endpoint.SendData(requestBytes);
            if (ret != NtStatus.STATUS_SUCCESS)
            {
                LogEvent(string.Format("Connection.Endpoint.SendData with error {0}", ret));
                return ret;
            }

            byte[] responseBytes;
            try
            {
                ret = Connection.Endpoint.ReceiveData(
                    TimeSpan.FromSeconds(SmbdConnection.ACTIVE_NEGOTIATION_TIMEOUT),
                    out responseBytes);
                if (ret != NtStatus.STATUS_SUCCESS)
                {
                    LogEvent(string.Format("Connection.Endpoint.ReceiveData with error {0}", ret));
                    return ret;
                }
            }
            catch (TimeoutException e)
            {
                LogEvent(string.Format("Do not get the SMBD negotiate response within {0} seconds", SmbdConnection.ACTIVE_NEGOTIATION_TIMEOUT));
                throw new TimeoutException(e.Message);
            }

            smbdNegotiateResponse = TypeMarshal.ToStruct<SmbdNegotiateResponse>(responseBytes);
            if ((NtStatus)smbdNegotiateResponse.Status != NtStatus.STATUS_SUCCESS)
            {
                LogEvent(string.Format("SMBDirect Negotiate response with status {0}", (NtStatus)smbdNegotiateResponse.Status));
                return (NtStatus)smbdNegotiateResponse.Status;
            }

            #region set connection parameters
            Connection.Protocol = SmbdVersion.V1;
            Connection.ReceiveCreditTarget = smbdNegotiateResponse.CreditsRequested;
            Connection.MaxReceiveSize = Smaller(Connection.MaxReceiveSize, smbdNegotiateResponse.PreferredSendSize);
            Connection.MaxSendSize = Smaller(Connection.MaxSendSize, smbdNegotiateResponse.MaxReceiveSize);
            Connection.MaxReadWriteSize = Smaller(smbdNegotiateResponse.MaxReadWriteSize, SmbdConnection.FLOOR_MAX_READ_WRITE_SIZE);
            Connection.SendCredits = smbdNegotiateResponse.CreditsGranted;
            #endregion

            Connection.Role = SmbdRole.ESTABLISHED;
            try
            {
                Connection.FragmentReassemblyBuffer = new byte[Connection.MaxFragmentedSize];
            }
            catch (OverflowException)
            {
                Connection.MaxFragmentedSize = smbdNegotiateResponse.MaxFragmentedSize;
                Connection.FragmentReassemblyBuffer = new byte[Connection.MaxFragmentedSize];
            }
            return (NtStatus)smbdNegotiateResponse.Status;
        }
 public NtStatus SmbdNegotiate(
     ushort sendCreditTarget,
     ushort receiveCreditMax,
     out SmbdNegotiateResponse response)
 {
     return client.SmbdNegotiate(
         SmbdVersion.V1,
         SmbdVersion.V1,
         0,
         sendCreditTarget,
         receiveCreditMax,
         (uint)testConfig.MaxSendSize,
         (uint)testConfig.MaxReceiveSize,
         (uint)testConfig.MaxFragmentedSize,
         out response
         );
 }
 public NtStatus SmbdNegotiate(
     uint preferredSendSize,
     uint maxReceiveSize,
     uint maxFragmentSize,
     out SmbdNegotiateResponse response
     )
 {
     return client.SmbdNegotiate(
         SmbdVersion.V1,
         SmbdVersion.V1,
         0,
         (ushort)testConfig.SendCreditTarget,
         (ushort)testConfig.ReceiveCreditMax,
         preferredSendSize,
         maxReceiveSize,
         maxFragmentSize,
         out response
         );
 }
 public NtStatus SmbdNegotiate(
     ushort creditsRequested,
     ushort receiveCreditsMax,
     uint preferredSendSize,
     uint maxReceiveSize,
     uint maxFragmentSize,
     out SmbdNegotiateResponse response,
     SmbdVersion minVersion = SmbdVersion.V1,
     SmbdVersion maxVersion = SmbdVersion.V1
     )
 {
     return client.SmbdNegotiate(
         minVersion,
         maxVersion,
         0,
         creditsRequested,
         receiveCreditsMax,
         preferredSendSize,
         maxReceiveSize,
         maxFragmentSize,
         out response
         );
 }