CompareByteArray() 공개 정적인 메소드

Compare two byte arrays
public static CompareByteArray ( byte array1, byte array2 ) : bool
array1 byte Byte array 1.
array2 byte Byte array 2.
리턴 bool
예제 #1
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;
            }
        }
예제 #2
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);
        }
예제 #3
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.");
        }
예제 #4
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.");
        }
        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;
            }
        }