示例#1
0
        /// <summary>
        /// output all addresses which are supported by the provider
        /// </summary>
        private void OutputAddressInfoSupportedByProvider(RdmaProviderInfo providerInfo)
        {
            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>
        /// 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;
        }