/// <summary>
        /// Disconnect
        /// </summary>
        /// <returns></returns>
        public void Disconnect()
        {
            lock (locker)
            {
                if (isConnected == false)
                {
                    return;
                }
                isConnected = false;
            }

            // disconnect
            rdmaConnector.Disconnect();

            // let notify thread stop
            rdmaNotificationSemaphore.Release();

            for (int i = 0; i < THREAD_COUNT; ++i)
            {
                //threadStopSemaphore.WaitOne(); // wait thread to stop
            }

            LogEvent("RDMA connection is disconnected by test suite.");
            this.logEndpointEvent = null;
        }
Exemple #2
0
        public void DisconnectRdma()
        {
            this.smbdClient.Disconnect();
            decoder   = new Smb2Decoder(Smb2Role.Client, new Dictionary <UInt64, Smb2CryptoInfo>());
            messageId = 0;

            logEvent = null;
        }
        /// <summary>
        /// Open adapter with local IP address
        /// </summary>
        /// <param name="providers"></param>
        /// <param name="localIpAddress"></param>
        /// <param name="ipFamily">IP Family, IPv4 or IPv6</param>
        /// <returns></returns>
        private static RdmaAdapter OpenAdapter(
            RdmaProviderInfo[] providers,
            string localIpAddress,
            AddressFamily ipFamily,
            SmbdLogEvent logEvent)
        {
            RdmaAdapter adapter;

            if (providers == null)
            {
                if (logEvent != null)
                {
                    logEvent("Providers list is null. Open adapter failed.");
                }
                return(null);
            }
            foreach (RdmaProviderInfo providerInfo in providers)
            {
                if (providerInfo.Provider == null)
                {
                    continue;
                }

                if (logEvent != null)
                {
                    logEvent(string.Format("Try to open adapter from provider \"{0}\" with specific IP Address: \"{1}\"",
                                           providerInfo.Path,
                                           localIpAddress));
                }

                OutputAddressInfoSupportedByProvider(providerInfo, logEvent);

                NtStatus status = (NtStatus)providerInfo.Provider.OpenAdapter(localIpAddress, (short)ipFamily, out adapter);
                if (status != NtStatus.STATUS_SUCCESS)
                {
                    if (logEvent != null)
                    {
                        logEvent(string.Format("Provider '{0}' does not support IP address \"{1}\".",
                                               providerInfo.Path,
                                               localIpAddress));
                    }
                    continue;
                }
                if (logEvent != null)
                {
                    logEvent(string.Format("Adapter on IP address \"{0}\" is open via provider '{1}'.",
                                           localIpAddress,
                                           providerInfo.Path));
                }
                return(adapter);
            }

            if (logEvent != null)
            {
                logEvent(string.Format("IP address \"{0}\" is not supported by all providers. Open adapter failed.", localIpAddress));
            }
            return(null);
        }
 public SmbdAdapter(
     ITestSite testSite,
     SmbdLogEvent logNotifyCompletion = null)
 {
     this.Initialize(testSite);
     this.client = new Smb2OverSmbdTestClient(
         testConfig.Smb2ConnectionTimeout,
         testConfig.RdmaLayerLoggingEnabled ? logNotifyCompletion : null);
 }
Exemple #5
0
 /// <summary>
 /// Disconnect
 /// </summary>
 public void Disconnect()
 {
     if (Connection != null && Connection.Endpoint != null)
     {
         Connection.Endpoint.Disconnect();
         Connection.Endpoint = null;
     }
     this.logEvent = null;
 }
 public SmbdAdapter(
     ITestSite testSite,
     SmbdLogEvent logNotifyCompletion = null)
 {
     this.Initialize(testSite);
     this.client = new Smb2OverSmbdTestClient(
         testConfig.Smb2ConnectionTimeout,
         testConfig.RdmaLayerLoggingEnabled ? logNotifyCompletion : null);
 }
Exemple #7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="smb2ConnectionTimeout">Timeout for SMB2 connection.</param>
        public Smb2OverSmbdTestClient(
            TimeSpan smb2ConnectionTimeout,
            SmbdLogEvent logEvent = null
            )
            : base(smb2ConnectionTimeout)
        {
            this.smb2ConnectionTimeout = smb2ConnectionTimeout;
            this.decoder = new Smb2Decoder(Smb2Role.Client, new Dictionary <UInt64, Smb2CryptoInfo>());

            this.smbdClient = new SmbdClient(
                logEvent);
            this.logEvent    = logEvent;
            ServerConnection = new SmbdConnection();

            messageId = 0;
            this.Smb2AvailableCredits = 1;
        }
        /// <summary>
        /// output all addresses which are supported by the provider
        /// </summary>
        private static void OutputAddressInfoSupportedByProvider(RdmaProviderInfo providerInfo, SmbdLogEvent logEvent)
        {
            if (logEvent == null)
            {
                return;
            }

            if (providerInfo == null)
            {
                logEvent("ProviderInfo is null.");
                return;
            }

            RdmaAddress[] addressList;
            NtStatus      status = (NtStatus)providerInfo.Provider.QueryAddressList(out addressList);

            if (status != NtStatus.STATUS_SUCCESS)
            {
                logEvent(string.Format("Return code of Provider.QueryAddressList is {0}", status));
                return;
            }

            if (addressList == null)
            {
                logEvent("The address list returned from Provider.QueryAddressList is null.");
                return;
            }

            if (addressList.Length == 0)
            {
                logEvent(string.Format("No address supported by provider \"{0}\".", providerInfo.Path));
                return;
            }

            logEvent(string.Format("Total {0} addresses supported by the provider \"{1}\":\n",
                                   addressList.Length,
                                   providerInfo.Path));
            int addressIndex = 0;

            foreach (RdmaAddress address in addressList)
            {
                if (address == null)
                {
                    continue;
                }

                if ((AddressFamily)address.Family == AddressFamily.InterNetwork)
                { // IPv4
                    logEvent(string.Format("{0}. {1}: {2}.{3}.{4}.{5}\n",
                                           ++addressIndex,
                                           AddressFamily.InterNetwork,
                                           (byte)address.Data[0],
                                           (byte)address.Data[1],
                                           (byte)address.Data[2],
                                           (byte)address.Data[3]));
                }
                else
                {
                    logEvent(string.Format("{0}. {1}", ++addressIndex, (AddressFamily)address.Family));
                }
            }
        }
        /// <summary>
        /// SmbdEndpoint constructor will load RDMA providers and initialize default connection values.
        /// </summary>
        /// <param name="inboundEntries">maximum number of outstanding Receive requests.</param>
        /// <param name="outboundEntries">maximum number of outstanding Send, SendAndInvalidate
        /// , Bind, Invalidate, Read, and Write requests.
        /// </param>
        /// <param name="inboundSegment">inbound segments limit</param>
        /// <param name="outboundSegment">outbound segments limit</param>
        /// <param name="inboundReadLimit">maximum inbound read limit for the local Network
        /// Direct adapter. This value can be zero if you do not support
        /// </param>
        /// <param name="outboundReadLimit"></param>
        /// <param name="inboundDataSize">Max Size of RDMA inbound data</param>
        /// <param name="logEvent">Delegate to log SMBD event</param>
        public SmbdConnectionEndpoint(
            uint inboundEntries,
            uint outboundEntries,
            uint inboundSegment,
            uint outboundSegment,
            uint inboundReadLimit,
            uint outboundReadLimit,
            uint inboundDataSize,
            SmbdLogEvent logEvent = null
            )
        {
            this.logEndpointEvent = logEvent;

            LogEvent("Loading the providers of registered network drivers.");
            initializeStatus = (NtStatus)RdmaProvider.LoadRdmaProviders(out rdmaProvidersList);

            this.inboundEntries       = inboundEntries;
            this.outboundEntries      = outboundEntries;
            this.inboundSegment       = inboundSegment;
            this.outboundSegment      = outboundSegment;
            this.inboundReadLimit     = inboundReadLimit;
            this.outboundReadLimit    = outboundReadLimit;
            this.completionQueueDepth = (inboundEntries + outboundEntries);
            this.inboundDataSize      = inboundDataSize;

            isConnected        = false;
            memoryWindowList   = new List <SmbdMemoryWindow>();
            receiveRequestList = new List <SmbdRequest>();

            locker = new Object();

            otherRequestResult   = new SyncFilterQueue <SmbdRequestResult>();
            receiveRequestResult = new SyncFilterQueue <SmbdRequestResult>();

            disconnectSemaphore = new Semaphore(0, 1);
            //threadStopSemaphore = new Semaphore(0, THREAD_COUNT);

            // one more for Semaphore Release when disconnection
            rdmaNotificationSemaphore = new Semaphore(0, (int)completionQueueDepth + 1);
            requestCount = 0;

            ReceivePostedCount = 0;

            #region output provider information
            if (initializeStatus != NtStatus.STATUS_SUCCESS)
            {
                LogEvent(string.Format("Load provider with error code: {0}", (NtStatus)initializeStatus));
                return;
            }
            if (rdmaProvidersList == null)
            {
                LogEvent("The returned providers list is NULL");
                return;
            }

            LogEvent(string.Format("{0} providers of registered network drivers have been load,", rdmaProvidersList.Length));
            int providerIndex = 0;
            foreach (RdmaProviderInfo info in rdmaProvidersList)
            {
                if (info != null)
                {
                    LogEvent(string.Format("Load provider {1}: {0}", info.Path, ++providerIndex));
                }
            }
            LogEvent("Loading providers is completed");
            #endregion
        }
Exemple #10
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="logSmbdEvent">Delegate to log SMBD event</param>
 public SmbdClient(SmbdLogEvent logSmbdEvent = null)
 {
     this.logEvent = logSmbdEvent;
 }
        /// <summary>
        /// output all addresses which are supported by the provider
        /// </summary>
        private static void OutputAddressInfoSupportedByProvider(RdmaProviderInfo providerInfo, SmbdLogEvent logEvent)
        {
            if (logEvent == null)
            {
                return;
            }

            if(providerInfo == null)
            {
                logEvent("ProviderInfo is null.");
                return;
            }

            RdmaAddress[] addressList;
            NtStatus status = (NtStatus)providerInfo.Provider.QueryAddressList(out addressList);

            if (status != NtStatus.STATUS_SUCCESS)
            {
                logEvent(string.Format("Return code of Provider.QueryAddressList is {0}", status));
                return;
            }

            if (addressList == null)
            {
                logEvent("The address list returned from Provider.QueryAddressList is null.");
                return;
            }

            if (addressList.Length == 0)
            {
                logEvent(string.Format("No address supported by provider \"{0}\".", providerInfo.Path));
                return;
            }

            logEvent(string.Format("Total {0} addresses supported by the provider \"{1}\":\n",
                addressList.Length,
                providerInfo.Path));
            int addressIndex = 0;
            foreach (RdmaAddress address in addressList)
            {
                if (address == null)
                {
                    continue;
                }

                if ((AddressFamily)address.Family == AddressFamily.InterNetwork)
                { // IPv4
                    logEvent(string.Format("{0}. {1}: {2}.{3}.{4}.{5}\n",
                        ++addressIndex,
                        AddressFamily.InterNetwork,
                        (byte)address.Data[0],
                        (byte)address.Data[1],
                        (byte)address.Data[2],
                        (byte)address.Data[3]));
                }
                else
                {
                    logEvent(string.Format("{0}. {1}", ++addressIndex, (AddressFamily)address.Family));
                }
            }
        }
        /// <summary>
        /// Open adapter with local IP address
        /// </summary>
        /// <param name="providers"></param>
        /// <param name="localIpAddress"></param>
        /// <param name="ipFamily">IP Family, IPv4 or IPv6</param>
        /// <returns></returns>
        private static RdmaAdapter OpenAdapter(
            RdmaProviderInfo[] providers,
            string localIpAddress,
            AddressFamily ipFamily,
            SmbdLogEvent logEvent)
        {
            RdmaAdapter adapter;

            if (providers == null)
            {
                if (logEvent != null)
                {
                    logEvent("Providers list is null. Open adapter failed.");
                }
                return null;
            }
            foreach (RdmaProviderInfo providerInfo in providers)
            {
                if (providerInfo.Provider == null)
                {
                    continue;
                }

                if (logEvent != null)
                {
                    logEvent(string.Format("Try to open adapter from provider \"{0}\" with specific IP Address: \"{1}\"",
                        providerInfo.Path,
                        localIpAddress));
                }

                OutputAddressInfoSupportedByProvider(providerInfo, logEvent);

                NtStatus status = (NtStatus)providerInfo.Provider.OpenAdapter(localIpAddress, (short)ipFamily, out adapter);
                if (status != NtStatus.STATUS_SUCCESS)
                {
                    if (logEvent != null)
                    {
                        logEvent(string.Format("Provider '{0}' does not support IP address \"{1}\".",
                            providerInfo.Path,
                            localIpAddress));
                    }
                    continue;
                }
                if (logEvent != null)
                {
                    logEvent(string.Format("Adapter on IP address \"{0}\" is open via provider '{1}'.",
                        localIpAddress,
                        providerInfo.Path));
                }
                return adapter;
            }

            if (logEvent != null)
            {
                logEvent(string.Format("IP address \"{0}\" is not supported by all providers. Open adapter failed.", localIpAddress));
            }
            return null;
        }
        /// <summary>
        /// Disconnect
        /// </summary>
        /// <returns></returns>
        public void Disconnect()
        {
            lock (locker)
            {
                if (isConnected == false)
                {
                    return;
                }
                isConnected = false;
            }

            // disconnect
            rdmaConnector.Disconnect();

            // let notify thread stop
            rdmaNotificationSemaphore.Release();

            for (int i = 0; i < THREAD_COUNT; ++i)
            {
                //threadStopSemaphore.WaitOne(); // wait thread to stop
            }

            LogEvent("RDMA connection is disconnected by test suite.");
            this.logEndpointEvent = null;
        }
        /// <summary>
        /// SmbdEndpoint constructor will load RDMA providers and initialize default connection values.
        /// </summary>
        /// <param name="inboundEntries">maximum number of outstanding Receive requests.</param>
        /// <param name="outboundEntries">maximum number of outstanding Send, SendAndInvalidate
        /// , Bind, Invalidate, Read, and Write requests.
        /// </param>
        /// <param name="inboundSegment">inbound segments limit</param>
        /// <param name="outboundSegment">outbound segments limit</param>
        /// <param name="inboundReadLimit">maximum inbound read limit for the local Network 
        /// Direct adapter. This value can be zero if you do not support
        /// </param>
        /// <param name="outboundReadLimit"></param>
        /// <param name="inboundDataSize">Max Size of RDMA inbound data</param>
        /// <param name="logEvent">Delegate to log SMBD event</param>
        public SmbdConnectionEndpoint(
            uint inboundEntries,
            uint outboundEntries,
            uint inboundSegment,
            uint outboundSegment,
            uint inboundReadLimit,
            uint outboundReadLimit,
            uint inboundDataSize,
            SmbdLogEvent logEvent = null
            )
        {
            this.logEndpointEvent = logEvent;

            LogEvent("Loading the providers of registered network drivers.");
            initializeStatus = (NtStatus)RdmaProvider.LoadRdmaProviders(out rdmaProvidersList);

            this.inboundEntries = inboundEntries;
            this.outboundEntries = outboundEntries;
            this.inboundSegment = inboundSegment;
            this.outboundSegment = outboundSegment;
            this.inboundReadLimit = inboundReadLimit;
            this.outboundReadLimit = outboundReadLimit;
            this.completionQueueDepth = (inboundEntries + outboundEntries);
            this.inboundDataSize = inboundDataSize;

            isConnected = false;
            memoryWindowList = new List<SmbdMemoryWindow>();
            receiveRequestList = new List<SmbdRequest>();

            locker = new Object();

            otherRequestResult = new SyncFilterQueue<SmbdRequestResult>();
            receiveRequestResult = new SyncFilterQueue<SmbdRequestResult>();

            disconnectSemaphore = new Semaphore(0, 1);
            //threadStopSemaphore = new Semaphore(0, THREAD_COUNT);

            // one more for Semaphore Release when disconnection
            rdmaNotificationSemaphore = new Semaphore(0, (int)completionQueueDepth + 1);
            requestCount = 0;

            ReceivePostedCount = 0;

            #region output provider information
            if (initializeStatus != NtStatus.STATUS_SUCCESS)
            {
                LogEvent(string.Format("Load provider with error code: {0}", (NtStatus)initializeStatus));
                return;
            }
            if (rdmaProvidersList == null)
            {
                LogEvent("The returned providers list is NULL");
                return;
            }

            LogEvent(string.Format("{0} providers of registered network drivers have been load,", rdmaProvidersList.Length));
            int providerIndex = 0;
            foreach (RdmaProviderInfo info in rdmaProvidersList)
            {
                if (info != null)
                {
                    LogEvent(string.Format("Load provider {1}: {0}", info.Path, ++providerIndex));
                }
            }
            LogEvent("Loading providers is completed");
            #endregion
        }
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="logSmbdEvent">Delegate to log SMBD event</param>
 public SmbdClient(SmbdLogEvent logSmbdEvent = null)
 {
     this.logEvent = logSmbdEvent;
 }
 /// <summary>
 /// Disconnect
 /// </summary>
 public void Disconnect()
 {
     if (Connection != null && Connection.Endpoint != null)
     {
         Connection.Endpoint.Disconnect();
         Connection.Endpoint = null;
     }
     this.logEvent = null;
 }