Exemplo n.º 1
0
 protected override void TestInitialize()
 {
     base.TestInitialize();
     fileName = SmbdUtilities.CreateRandomFileName();
     sutProtocolControlAdapter = BaseTestSite.GetAdapter <ISutProtocolControlAdapter>();
     SmbdUtilities.LogTestCaseDescription(BaseTestSite);
 }
Exemplo n.º 2
0
        protected string CreateRandomFileName()
        {
            string fileName = SmbdUtilities.CreateRandomFileName();

            fileNameList.Add(fileName);
            return(fileName);
        }
Exemplo n.º 3
0
 protected override void TestInitialize()
 {
     base.TestInitialize();
     sutProtocolControlAdapter = BaseTestSite.GetAdapter <ISutProtocolControlAdapter>();
     this.smbdAdapter          = new SmbdAdapter(BaseTestSite, LogSmbdEndpointEvent);
     fileNameList = new List <string>();
     SmbdUtilities.LogTestCaseDescription(BaseTestSite);
 }
 protected override void TestInitialize()
 {
     this.testConfig        = new TestConfig(BaseTestSite);
     this.mainChannelClient = new Smb2OverSmbdTestClient(
         testConfig.Smb2ConnectionTimeout);
     this.alternativeChannelClient = new Smb2OverSmbdTestClient(
         testConfig.Smb2ConnectionTimeout);
     SmbdUtilities.LogTestCaseDescription(BaseTestSite);
 }
Exemplo n.º 5
0
        public void ValidateFileContent(byte[] expectedContent)
        {
            uint sizePerRead      = (uint)smbdAdapter.Smb2MaxReadSize;
            uint expectedFileSize = (uint)expectedContent.Length;

            // SMB2 Read file
            SmbdBufferDescriptorV1 descp;
            NtStatus status = smbdAdapter.SmbdRegisterBuffer(
                sizePerRead,
                SmbdBufferReadWrite.RDMA_WRITE_PERMISSION_FOR_READ_FILE,
                out descp);

            BaseTestSite.Assert.AreEqual(
                NtStatus.STATUS_SUCCESS,
                status,
                "Register buffer should succeed.");

            // send each read request according SMB2 read file limit
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Read content from file over RDMA.");
            uint offset = 0;

            while (offset < expectedFileSize)
            {
                byte[] channelInfo = TypeMarshal.ToBytes <SmbdBufferDescriptorV1>(descp);

                uint length = sizePerRead;
                if (offset + length > expectedFileSize)
                {
                    length = expectedFileSize - offset;
                }

                READ_Response readResponse;
                byte[]        readData;
                status = (NtStatus)smbdAdapter.Smb2ReadOverRdmaChannel(
                    (UInt64)offset,
                    (uint)length,
                    channelInfo,
                    out readResponse,
                    out readData);

                BaseTestSite.Assert.AreEqual(
                    NtStatus.STATUS_SUCCESS,
                    status,
                    "SMB2 READ over RDMA should succeed.");

                byte[] readFileContent = new byte[length];
                smbdAdapter.SmbdReadRegisteredBuffer(readFileContent, descp);
                BaseTestSite.Assert.IsTrue(
                    SmbdUtilities.CompareByteArray(expectedContent.Skip((int)offset).Take((int)length).ToArray(), readFileContent),
                    "Check content of file");

                offset += sizePerRead;
            }
        }
        /// <summary>
        /// Write file content over RDMA. The file content will be writen with specific number of operations.
        /// The total size of the write content is SMB2 negotiated MaxWriteize, so content size
        /// in each SMB2 WRITE request is ( MaxWriteSize / operationCount )
        /// </summary>
        /// <param name="operationCount">count of SMB2 WRITE operation</param>
        public void WriteOverRdma(uint operationCount = 1)
        {
            string fileName = SmbdUtilities.CreateRandomFileName();

            InitSmbdConnectionForTestCases(fileName);

            uint writeSize = smbdAdapter.Smb2MaxWriteSize / operationCount;
            uint totalSize = writeSize * operationCount;

            // SMB2 Write file
            byte[] fileContent = Encoding.ASCII.GetBytes(Smb2Utility.CreateRandomStringInByte((int)writeSize));

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Send each write request according SMB2 write file limit.");
            for (int i = 0; i < operationCount; ++i)
            {
                // register memory and get buffer descriptor
                SmbdBufferDescriptorV1 descp;
                smbdAdapter.SmbdRegisterBuffer(
                    writeSize,
                    SmbdBufferReadWrite.RDMA_READ_PERMISSION_FOR_WRITE_FILE,
                    out descp
                    );
                smbdAdapter.SmbdWriteRegisteredBuffer(fileContent, descp);
                byte[] channelInfo = TypeMarshal.ToBytes <SmbdBufferDescriptorV1>(descp);

                BaseTestSite.Log.Add(LogEntryKind.TestStep, "Write content to file over RDMA.");
                WRITE_Response writeResponse;
                NtStatus       status = (NtStatus)smbdAdapter.Smb2WriteOverRdmaChannel(
                    (UInt64)i * writeSize,
                    channelInfo,
                    writeSize,
                    out writeResponse
                    );
                BaseTestSite.Assert.AreEqual <NtStatus>(
                    NtStatus.STATUS_SUCCESS,
                    status,
                    "Status of SMB2 Write File offset {0} is {1}", i * writeSize, status);
                BaseTestSite.Assert.AreEqual <uint>(
                    (uint)writeSize,
                    writeResponse.Count,
                    "DataLength in WRITE response is {0}", writeResponse.Count);
            }

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Validate file content.");
            ValidateFileContent(fileContent, totalSize);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Close file.");
            smbdAdapter.Smb2CloseFile();
        }
        public void OperationWithSpecifiedCredits(ushort credits)
        {
            // define test data for this test case
            ushort receiveCreditMax = credits;
            ushort sendCreditTarget = credits;

            uint size = smbdAdapter.TestConfig.ModerateFileSizeInByte;

            string fileName = SmbdUtilities.CreateRandomFileName();

            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 with server.");
            SmbdNegotiateResponse response;

            status = smbdAdapter.SmbdNegotiate(sendCreditTarget, receiveCreditMax, out response);
            BaseTestSite.Assert.AreEqual <NtStatus>(NtStatus.STATUS_SUCCESS, status, "Status of SMBD negotiate is {0}", status);
            BaseTestSite.Assert.IsTrue(response.MaxFragmentedSize >= SmbdConnection.FLOOR_MAX_FRAGMENTED_SIZE
                                       , "MaxFragmentedSize in negotiate response is {0}", response.MaxFragmentedSize); // check the MaxFragementSize

            // SMB2 Negotiate, Session Setup, Tree Connect and Open File
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Establish SMB2 connection and open file " + fileName);
            status = smbdAdapter.Smb2EstablishSessionAndOpenFile(fileName);
            BaseTestSite.Assert.AreEqual <NtStatus>(NtStatus.STATUS_SUCCESS, status, "Status of SMB2 establish session and open file is {0}", status);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Write a moderate size of data to the file.");
            byte[]         data = new byte[size];
            WRITE_Response writeResponse;

            status = (NtStatus)smbdAdapter.Smb2Write(0, data, out writeResponse);
            BaseTestSite.Assert.AreEqual <NtStatus>(NtStatus.STATUS_SUCCESS, status, "Status of SMB2 write File is {0}", status);
            BaseTestSite.Assert.AreEqual <uint>(size, writeResponse.Count, "Size of written file is {0}", writeResponse.Count);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Close file and disconnect from server.");
            smbdAdapter.Smb2CloseFile();
            // disconnect
            smbdAdapter.DisconnectRdma();
        }
        public void Smb2Multichannel_2Channels_DiffTransport()
        {
            uint   treeId;
            FILEID fileId;

            byte[] fileContent;
            string fileName = SmbdUtilities.CreateRandomFileName();

            WriteFromMainChannel(
                IPAddress.Parse(testConfig.ServerRNicIp),
                IPAddress.Parse(testConfig.ClientRNicIp),
                fileName,
                testConfig.LargeFileSizeInByte,
                out fileContent,
                out treeId,
                out fileId
                );
            ReadFromAlternativeChannel(
                fileContent,
                testConfig.LargeFileSizeInByte,
                treeId,
                fileId
                );
        }
Exemplo n.º 9
0
        /// <summary>
        /// Read from alternative channel over RDMA
        /// </summary>
        /// <param name="content">File content to be compared.</param>
        /// <param name="lengthRead">Data length to be read.</param>
        /// <param name="treeId">Tree Connect Id.</param>
        /// <param name="fileId">File Id.</param>
        private void ReadFromAlternativeChannel(
            byte[] content,
            uint lengthRead,
            uint treeId,
            FILEID fileId
            )
        {
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Read from alternative channel over RDMA.");
            BaseTestSite.Log.Add(LogEntryKind.Debug, "ServerRNicIp: " + testConfig.ServerRNicIp);
            BaseTestSite.Log.Add(LogEntryKind.Debug, "ClientRNicIp: " + testConfig.ClientRNicIp);
            BaseTestSite.Log.Add(LogEntryKind.Debug, "Data length to be read: " + lengthRead.ToString());

            NtStatus status;

            #region Query Network information
            NETWORK_INTERFACE_INFO_Response[] networkInterfaceInfos;
            status = (NtStatus)mainChannelClient.Smb2QueryNetworkInterfaceInfo(out networkInterfaceInfos);

            BaseTestSite.Assert.AreEqual <NtStatus>(
                NtStatus.STATUS_SUCCESS,
                status,
                "Status of Query Network Interface Info is {0}", status);
            bool containRdmaNicIPAddress = false;
            foreach (NETWORK_INTERFACE_INFO_Response networkInterfaceInfo in networkInterfaceInfos)
            {
                NETWORK_INTERFACE_INFO_Response_Capabilities capability = networkInterfaceInfo.Capability;
                capability |= NETWORK_INTERFACE_INFO_Response_Capabilities.RDMA_CAPABLE;
                if (capability == networkInterfaceInfo.Capability &&
                    testConfig.ServerRNicIp.Equals(networkInterfaceInfo.AddressStorage.Address))
                {
                    containRdmaNicIPAddress = true;
                    break;
                }
            }
            if (!containRdmaNicIPAddress)
            {
                BaseTestSite.Assert.Fail("No RDMA capable network can be found.");
            }
            #endregion

            IPAddress clientIp = IPAddress.Parse(testConfig.ClientRNicIp);
            status = alternativeChannelClient.ConnectToServerOverRDMA(
                testConfig.ClientRNicIp,
                testConfig.ServerRNicIp,
                testConfig.SmbdTcpPort,
                clientIp.AddressFamily,
                testConfig.InboundEntries,
                testConfig.OutboundEntries,
                testConfig.InboundReadLimit,
                testConfig.MaxReceiveSize);

            BaseTestSite.Assert.AreEqual <NtStatus>(
                NtStatus.STATUS_SUCCESS,
                status,
                "Status of ConnectToServerOverRDMA is {0}", status);

            // SMBD negotiate
            SmbdNegotiateResponse response;
            status = alternativeChannelClient.SmbdNegotiate(
                SmbdVersion.V1,
                SmbdVersion.V1,
                0,
                (ushort)testConfig.SendCreditTarget,
                (ushort)testConfig.ReceiveCreditMax,
                (uint)testConfig.MaxSendSize,
                (uint)testConfig.MaxReceiveSize,
                (uint)testConfig.MaxFragmentedSize,
                out response
                );
            BaseTestSite.Assert.AreEqual <NtStatus>(
                NtStatus.STATUS_SUCCESS,
                status,
                "Status of SmbdNegotiate is {0}", status);

            // SMB2 Negotiate
            DialectRevision[] negotiatedDialects = new DialectRevision[] { DialectRevision.Smb30 };
            DialectRevision   selectedDialect;
            status = (NtStatus)alternativeChannelClient.Smb2Negotiate(negotiatedDialects, out selectedDialect);
            BaseTestSite.Assert.AreEqual <NtStatus>(NtStatus.STATUS_SUCCESS, status, "Status of SMB2 Negotiate is {0}", status);


            // SMB2 Session Setup
            status = (NtStatus)alternativeChannelClient.Smb2AlternativeChannelSessionSetup(
                mainChannelClient,
                testConfig.DomainName,
                testConfig.UserName,
                testConfig.Password,
                testConfig.ServerName
                );
            BaseTestSite.Assert.AreEqual <NtStatus>(NtStatus.STATUS_SUCCESS, status, "Status of SMB2 Session Setup is {0}", status);
            // Set treeId and fileId
            alternativeChannelClient.TreeId = treeId;
            alternativeChannelClient.FileId = fileId;

            // Send each read request according to SMB2 read file limit
            uint maxReadSize = alternativeChannelClient.Smb2MaxReadSize;
            uint offset      = 0;
            while (offset < lengthRead)
            {
                uint length = maxReadSize;
                if (offset + length > lengthRead)
                {
                    length = lengthRead - offset;
                }

                // Register Memory for RDMA read
                byte[] directMemory = new byte[length];
                SmbdBufferDescriptorV1 descp;
                alternativeChannelClient.SmbdRegisterBuffer(
                    length,
                    SmbdBufferReadWrite.RDMA_READ_WRITE_PERMISSION_FOR_WRITE_READ_FILE,
                    testConfig.ReversedBufferDescriptor,
                    out descp);
                byte[] channelInfo = TypeMarshal.ToBytes <SmbdBufferDescriptorV1>(descp);

                // Read over RDMA channel
                READ_Response readResponse;
                byte[]        readData;
                status = (NtStatus)alternativeChannelClient.Smb2ReadOverRdmaChannel(
                    (UInt64)offset,
                    (uint)length,
                    channelInfo,
                    out readResponse,
                    out readData
                    );

                BaseTestSite.Assert.AreEqual <NtStatus>(NtStatus.STATUS_SUCCESS, status, "Status of SMB2 Read File is {0}", status);

                alternativeChannelClient.SmbdReadRegisteredBuffer(directMemory, descp);
                BaseTestSite.Assert.IsTrue(SmbdUtilities.CompareByteArray(directMemory, content), "Check file content");

                offset += length;
            }

            status = (NtStatus)alternativeChannelClient.Smb2CloseFile();
            BaseTestSite.Assert.AreEqual <NtStatus>(NtStatus.STATUS_SUCCESS, status, "Status of SMB2 Close file is {0}", status);

            alternativeChannelClient.Smb2TreeDisconnect();
            BaseTestSite.Assert.AreEqual <NtStatus>(NtStatus.STATUS_SUCCESS, status, "Status of SMB2 Tree Disconnect is {0}", status);

            alternativeChannelClient.Smb2LogOff();
            BaseTestSite.Assert.AreEqual <NtStatus>(NtStatus.STATUS_SUCCESS, status, "Status of SMB2 Logoff is {0}", status);
        }
Exemplo n.º 10
0
        public void Smb2OverRdma_Read_SMB2_CHANNEL_RDMA_V1()
        {
            EstablishConnectionAndOpenFile(fileName);

            uint fileSize = smbdAdapter.Smb2MaxReadSize;

            byte[] fileContent = Smb2Utility.CreateRandomByteArray((int)fileSize);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Register memory and get buffer descriptor for SMB2 WRITE");
            SmbdBufferDescriptorV1 descp;
            NtStatus status = smbdAdapter.SmbdRegisterBuffer(
                fileSize,
                SmbdBufferReadWrite.RDMA_READ_PERMISSION_FOR_WRITE_FILE,
                out descp);

            BaseTestSite.Assert.AreEqual(
                NtStatus.STATUS_SUCCESS,
                status,
                "Register buffer should succeed.");

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Write content to file over RDMA.");
            status = Smb2WriteOverRdma(fileName, fileContent, Channel_Values.CHANNEL_RDMA_V1_INVALIDATE, descp);
            BaseTestSite.Assert.AreEqual <NtStatus>(
                NtStatus.STATUS_SUCCESS,
                status,
                "SMB2 WRITE over RDMA should succeed.");

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Register memory and get buffer descriptor for SMB2 READ.");
            status = smbdAdapter.SmbdRegisterBuffer(
                fileSize,
                SmbdBufferReadWrite.RDMA_WRITE_PERMISSION_FOR_READ_FILE,
                out descp);
            BaseTestSite.Assert.AreEqual(
                NtStatus.STATUS_SUCCESS,
                status,
                "Register buffer should succeed.");

            byte[] channelInfo = TypeMarshal.ToBytes <SmbdBufferDescriptorV1>(descp);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Read content from file over RDMA.");
            READ_Response readResponse;

            byte[] readData;
            status = (NtStatus)smbdAdapter.Smb2ReadOverRdmaChannel(
                0,
                (uint)fileSize,
                channelInfo,
                out readResponse,
                out readData,
                Channel_Values.CHANNEL_RDMA_V1);

            BaseTestSite.Assert.AreEqual <NtStatus>(
                NtStatus.STATUS_SUCCESS,
                status,
                "SMB2 READ over RDMA should succeed.");

            byte[] readContent = new byte[fileSize];
            smbdAdapter.SmbdReadRegisteredBuffer(readContent, descp);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Verify the read content same as the original one on server.");
            BaseTestSite.Assert.IsTrue(
                SmbdUtilities.CompareByteArray(fileContent, readContent),
                "Content read should be identical with original on server.");

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Send SMB2 READ using same descriptor.");
            status = (NtStatus)smbdAdapter.Smb2ReadOverRdmaChannel(
                0,
                (uint)fileSize,
                channelInfo,
                out readResponse,
                out readData,
                Channel_Values.CHANNEL_RDMA_V1);

            BaseTestSite.Assert.AreEqual <NtStatus>(
                NtStatus.STATUS_SUCCESS,
                status,
                "SMB2 READ over RDMA should succeed.");

            smbdAdapter.SmbdReadRegisteredBuffer(readContent, descp);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Verify the read content same as the original one on server.");
            BaseTestSite.Assert.IsTrue(
                SmbdUtilities.CompareByteArray(fileContent, readContent),
                "Content read should be identical with original on server.");
        }
Exemplo n.º 11
0
        public void BVT_Smb2OverRdma_Smb302_Read_SMB2_CHANNEL_RDMA_V1_INVALIDATE()
        {
            EstablishConnectionAndOpenFile(fileName, Smb302AboveDialects);

            uint fileSize = smbdAdapter.Smb2MaxReadSize;

            byte[] fileContent = Smb2Utility.CreateRandomByteArray((int)fileSize);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Register memory and get buffer descriptor for SMB2 WRITE");
            SmbdBufferDescriptorV1 descp;
            NtStatus status = smbdAdapter.SmbdRegisterBuffer(
                fileSize,
                SmbdBufferReadWrite.RDMA_READ_PERMISSION_FOR_WRITE_FILE,
                out descp);

            BaseTestSite.Assert.AreEqual(
                NtStatus.STATUS_SUCCESS,
                status,
                "Register buffer should succeed.");

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Write content to file over RDMA.");
            status = Smb2WriteOverRdma(fileName, fileContent, Channel_Values.CHANNEL_RDMA_V1_INVALIDATE, descp);
            BaseTestSite.Assert.AreEqual <NtStatus>(
                NtStatus.STATUS_SUCCESS,
                status,
                "SMB2 WRITE over RDMA should succeed.");

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Register memory and get buffer descriptor for SMB2 READ.");
            status = smbdAdapter.SmbdRegisterBuffer(
                fileSize,
                SmbdBufferReadWrite.RDMA_WRITE_PERMISSION_FOR_READ_FILE,
                out descp);
            BaseTestSite.Assert.AreEqual(
                NtStatus.STATUS_SUCCESS,
                status,
                "Register buffer should succeed.");
            byte[] channelInfo = TypeMarshal.ToBytes <SmbdBufferDescriptorV1>(descp);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Read content from file over RDMA.");
            READ_Response readResponse;

            byte[] readData;
            status = (NtStatus)smbdAdapter.Smb2ReadOverRdmaChannel(
                0,
                (uint)fileSize,
                channelInfo,
                out readResponse,
                out readData,
                Channel_Values.CHANNEL_RDMA_V1_INVALIDATE);

            BaseTestSite.Assert.AreEqual <NtStatus>(
                NtStatus.STATUS_SUCCESS,
                status,
                "SMB2 READ over RDMA should succeed.");

            byte[] readContent = new byte[fileSize];
            smbdAdapter.SmbdReadRegisteredBuffer(readContent, descp);

            BaseTestSite.Assert.IsTrue(
                SmbdUtilities.CompareByteArray(fileContent, readContent),
                "Content read should be identical with original on server.");

            try
            {
                status = (NtStatus)smbdAdapter.Smb2ReadOverRdmaChannel(
                    0,
                    (uint)fileSize,
                    channelInfo,
                    out readResponse,
                    out readData,
                    Channel_Values.CHANNEL_RDMA_V1_INVALIDATE);
            }
            catch
            {
                BaseTestSite.Log.Add(LogEntryKind.Debug, "Wait for connection to be terminated ");
                smbdAdapter.WaitRdmaDisconnect();
            }

            BaseTestSite.Assert.IsFalse(smbdAdapter.ClientConnection.Endpoint.IsConnected, "Connection should be terminated when accessing a memory window which is already invalidated.");
        }
Exemplo n.º 12
0
        public void Negotiate_Version(
            SmbdVersion minVer,
            SmbdVersion maxVer)
        {
            const ushort CREDIT_REQUESTED   = 10;
            const ushort RECEIVE_CREDIT_MAX = 10;
            const uint   MAX_SEND_SIZE      = 1024;
            const uint   MAX_RECEIVE_SIZE   = 1024;
            const uint   MAX_FRAGMENT_SIZE  = 131072;

            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, string.Format("SMBD Negotiate, MinVersion: {0}; MaxVersion: {1}", minVer.ToString(), maxVer.ToString()));
            SmbdNegotiateResponse response;

            status = smbdAdapter.SmbdNegotiate(
                CREDIT_REQUESTED,
                RECEIVE_CREDIT_MAX,
                MAX_SEND_SIZE,
                MAX_RECEIVE_SIZE,
                MAX_FRAGMENT_SIZE,
                out response,
                minVer,
                maxVer
                );

            // try to negotiate on SMB2
            string fileName = SmbdUtilities.CreateRandomFileName();

            // "<3> Section 3.1.5.6:  Windows Server 2012 fails the Negotiate Request Message with STATUS_NOT_SUPPORTED if MinVersion or MaxVersion is not 0x0100"
            if (smbdAdapter.TestConfig.Platform == Platform.WindowsServer2012)
            {
                if (minVer == SmbdVersion.V1 &&
                    maxVer == SmbdVersion.V1)
                {
                    BaseTestSite.Assert.AreEqual <NtStatus>(
                        NtStatus.STATUS_SUCCESS,
                        status,
                        "SMBD Negotiate should succeed");

                    BaseTestSite.Log.Add(LogEntryKind.TestStep, "Establish SMB2 connection and open file " + fileName);
                    status = smbdAdapter.Smb2EstablishSessionAndOpenFile(fileName);
                    BaseTestSite.Assert.AreEqual <NtStatus>(
                        NtStatus.STATUS_SUCCESS,
                        status,
                        "Smb2EstablishSessionAndOpenFile should success");
                }
                else
                {
                    BaseTestSite.Assert.AreEqual <NtStatus>(
                        NtStatus.STATUS_NOT_SUPPORTED,
                        status,
                        "Status of SMBD negotiate {0}", status);

                    try
                    {
                        BaseTestSite.Log.Add(LogEntryKind.TestStep, "Try to establish SMB2 connection and open file " + fileName);
                        status = smbdAdapter.Smb2EstablishSessionAndOpenFile(fileName);
                        BaseTestSite.Assert.AreNotEqual <NtStatus>(
                            NtStatus.STATUS_SUCCESS,
                            status,
                            "Status of Smb2EstablishSessionAndOpenFile is {0}", status);
                    }
                    catch (TimeoutException e)
                    {
                        BaseTestSite.Assert.Pass("Cannot send or receive packets from peer. \nException: {0}\n{1}", e.Message, e.StackTrace);
                    }
                }
            }
            else
            {
                if (minVer <= SmbdVersion.V1 &&
                    maxVer >= SmbdVersion.V1)
                {
                    BaseTestSite.Assert.AreEqual <NtStatus>(
                        NtStatus.STATUS_SUCCESS,
                        status,
                        "SMBD Negotiate should succeed");

                    BaseTestSite.Log.Add(LogEntryKind.TestStep, "Establish SMB2 connection and open file " + fileName);
                    status = smbdAdapter.Smb2EstablishSessionAndOpenFile(fileName);
                    BaseTestSite.Assert.AreEqual <NtStatus>(
                        NtStatus.STATUS_SUCCESS,
                        status,
                        "Smb2EstablishSessionAndOpenFile should success");
                }
                else
                {
                    BaseTestSite.Assert.AreEqual <NtStatus>(
                        NtStatus.STATUS_NOT_SUPPORTED,
                        status,
                        "Status of SMBD negotiate {0}", status);

                    try
                    {
                        BaseTestSite.Log.Add(LogEntryKind.TestStep, "Try to establish SMB2 connection and open file " + fileName);
                        status = smbdAdapter.Smb2EstablishSessionAndOpenFile(fileName);
                        BaseTestSite.Assert.AreNotEqual <NtStatus>(
                            NtStatus.STATUS_SUCCESS,
                            status,
                            "Status of Smb2EstablishSessionAndOpenFile is {0}", status);
                    }
                    catch (TimeoutException e)
                    {
                        BaseTestSite.Assert.Pass("Cannot send or receive packets from peer. \nException: {0}\n{1}", e.Message, e.StackTrace);
                    }
                }
            }
        }
Exemplo n.º 13
0
 protected override void TestInitialize()
 {
     this.smbdAdapter = new SmbdAdapter(BaseTestSite, LogSmbdEndpointEvent);
     SmbdUtilities.LogTestCaseDescription(BaseTestSite);
 }
        public void Smb2OverRdmaChannel_ReadWriteMultipleBufferDescriptorList()
        {
            InitSmbdConnectionForTestCases(smbdAdapter.TestConfig.TestFileName_LargeFile);
            uint size = smbdAdapter.Smb2MaxReadSize;

            if (size > smbdAdapter.Smb2MaxWriteSize)
            {
                size = smbdAdapter.Smb2MaxWriteSize;
            }
            int  bufferCount  = ushort.MaxValue / SmbdBufferDescriptorV1.SIZE; // SMB2 max support channel info size
            uint bufferLength = (uint)(size / bufferCount + 1);                // buffer length of each buffer descriptor

            byte[]   channelInfo  = new byte[SmbdBufferDescriptorV1.SIZE * bufferCount];
            byte[]   writeContent = Encoding.ASCII.GetBytes(Smb2Utility.CreateRandomStringInByte((int)size));
            byte[]   readContent  = new byte[size];
            NtStatus status;

            #region SMB2 Write file
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Register memory and get buffer descriptor for SMB2 WRITE");
            SmbdBufferDescriptorV1[] writeDescp = new SmbdBufferDescriptorV1[bufferCount];
            for (int i = 0; i < bufferCount; ++i)
            {
                smbdAdapter.SmbdRegisterBuffer(
                    bufferLength,
                    SmbdBufferReadWrite.RDMA_READ_PERMISSION_FOR_WRITE_FILE,
                    out writeDescp[i]);
                byte[] channelInfoBlock = TypeMarshal.ToBytes <SmbdBufferDescriptorV1>(writeDescp[i]);
                Array.Copy(
                    channelInfoBlock,
                    0,
                    channelInfo,
                    SmbdBufferDescriptorV1.SIZE * i,
                    SmbdBufferDescriptorV1.SIZE);
            }
            // copy write content
            for (int index = 0, writeOffset = 0;
                 index < bufferCount && writeOffset < writeContent.Length;
                 ++index, writeOffset += (int)bufferLength)
            {
                int length = (int)bufferLength;
                if (length + writeOffset > writeContent.Length)
                {
                    length = writeContent.Length - writeOffset;
                }
                byte[] buffer = new byte[length];
                Array.Copy(writeContent, writeOffset, buffer, 0, length);
                smbdAdapter.SmbdWriteRegisteredBuffer(buffer, writeDescp[index]);
            }

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Write content to file over RDMA.");
            WRITE_Response writeResponse;
            status = (NtStatus)smbdAdapter.Smb2WriteOverRdmaChannel(
                0,
                channelInfo,
                size,
                out writeResponse
                );
            BaseTestSite.Assert.AreEqual <NtStatus>(
                NtStatus.STATUS_SUCCESS,
                status,
                "Status of SMB2 Write File is {0}", status);
            BaseTestSite.Assert.AreEqual <uint>(
                (uint)size,
                writeResponse.Count,
                "DataLength in WRITE response is {0}", writeResponse.Count);

            #endregion


            #region Read file from server
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Register memory and get buffer descriptor for SMB2 WRITE");
            SmbdBufferDescriptorV1[] readDescp = new SmbdBufferDescriptorV1[bufferCount];
            for (int i = 0; i < bufferCount; ++i)
            {
                smbdAdapter.SmbdRegisterBuffer(
                    bufferLength,
                    SmbdBufferReadWrite.RDMA_WRITE_PERMISSION_FOR_READ_FILE,
                    out readDescp[i]);
                byte[] channelInfoBlock = TypeMarshal.ToBytes <SmbdBufferDescriptorV1>(readDescp[i]);
                Array.Copy(
                    channelInfoBlock,
                    0,
                    channelInfo,
                    SmbdBufferDescriptorV1.SIZE * i,
                    SmbdBufferDescriptorV1.SIZE);
            }

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Read content from file over RDMA.");
            READ_Response readResponse;
            byte[]        readData;
            status = (NtStatus)smbdAdapter.Smb2ReadOverRdmaChannel(
                0,
                size,
                channelInfo,
                out readResponse,
                out readData
                );
            BaseTestSite.Assert.AreEqual <NtStatus>(
                NtStatus.STATUS_SUCCESS,
                status,
                "Status of SMB2 Read File is {0}", status);
            BaseTestSite.Assert.AreEqual <uint>(
                0,
                readResponse.DataLength,
                "DataLength in READ response is {0}", readResponse.DataLength);
            BaseTestSite.Assert.AreEqual <int>(
                0,
                readData.Length,
                "Data length of content in response is {0}", readData.Length);
            BaseTestSite.Assert.AreEqual <byte>(
                80,
                readResponse.DataOffset,
                "DataOffset in response is {0}", readResponse.DataOffset);
            BaseTestSite.Assert.AreEqual <uint>(
                size,
                readResponse.DataRemaining,
                "DataRemaining in response is {0}", readResponse.DataRemaining);

            // read content
            for (int index = 0, readOffset = 0;
                 index < bufferCount && readOffset < readContent.Length;
                 ++index, readOffset += (int)bufferLength)
            {
                int length = (int)bufferLength;
                if (length + readOffset > readContent.Length)
                {
                    length = writeContent.Length - readOffset;
                }
                byte[] buffer = new byte[length];
                smbdAdapter.SmbdReadRegisteredBuffer(buffer, readDescp[index]);
                Array.Copy(buffer, 0, readContent, readOffset, length);
            }
            #endregion

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Check the read content is same as the one written into the file.");
            BaseTestSite.Assert.IsTrue(
                SmbdUtilities.CompareByteArray(writeContent, readContent),
                "Check content of file");

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Close file.");
            smbdAdapter.Smb2CloseFile();
        }
        public void ValidateFileContent(byte[] content, uint fileSize)
        {
            uint readSize = (uint)content.Length;
            // SMB2 Read file
            SmbdBufferDescriptorV1 descp;

            smbdAdapter.SmbdRegisterBuffer(
                readSize,
                SmbdBufferReadWrite.RDMA_WRITE_PERMISSION_FOR_READ_FILE,
                out descp);

            // send each read request according to SMB2 read file limit
            uint offset = 0;

            while (offset < fileSize)
            {
                byte[] channelInfo = TypeMarshal.ToBytes <SmbdBufferDescriptorV1>(descp);

                uint length = readSize;
                if (offset + length > fileSize)
                {
                    length = fileSize - offset;
                }
                READ_Response readResponse;
                byte[]        readData;
                NtStatus      status = (NtStatus)smbdAdapter.Smb2ReadOverRdmaChannel(
                    (UInt64)offset,
                    (uint)length,
                    channelInfo,
                    out readResponse,
                    out readData
                    );
                BaseTestSite.Assert.AreEqual <NtStatus>(
                    NtStatus.STATUS_SUCCESS,
                    status,
                    "Status of SMB2 Read File is {0}", status);
                BaseTestSite.Assert.AreEqual <uint>(
                    (uint)length,
                    readResponse.DataRemaining,
                    "DataRemaining in READ response is {0}", readResponse.DataRemaining);
                BaseTestSite.Assert.AreEqual <int>(
                    0,
                    readData.Length,
                    "Data length of content in response is {0}", readData.Length);
                BaseTestSite.Assert.AreEqual <byte>(
                    80,
                    readResponse.DataOffset,
                    "DataOffset in response is {0}", readResponse.DataOffset);
                BaseTestSite.Assert.AreEqual <uint>(
                    0,
                    readResponse.DataLength,
                    "DataLength in response is {0}", readResponse.DataLength);

                byte[] readFileContent = new byte[readSize];
                smbdAdapter.SmbdReadRegisteredBuffer(readFileContent, descp);
                BaseTestSite.Assert.IsTrue(
                    SmbdUtilities.CompareByteArray(content, readFileContent),
                    "Check content of file");


                offset += readSize;
            }
        }