private void SWNAsyncNotification_IPChange(SwnMessageType messageType)
        {
            int  ret    = 0;
            uint callId = 0;
            WITNESS_INTERFACE_INFO registerInterface;
            string server = TestConfig.ClusteredScaleOutFileServerName;

            #region Get the file server IP and access it through SMB2
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Get the file server Ip and access it through SMB2.");
            IPAddress currentAccessIp = SWNTestUtility.GetCurrentAccessIP(server);
            BaseTestSite.Assert.AreNotEqual(null, currentAccessIp, "IP address of the file server should NOT be empty");
            BaseTestSite.Log.Add(LogEntryKind.Debug, "IP address of the file server is {0}.", currentAccessIp.ToString());

            #endregion

            #region Get interface list to register.
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Get interface list to register.");
            DoUntilSucceed(() => SWNTestUtility.BindServer(swnClientForInterface, currentAccessIp,
                                                           TestConfig.DomainName, TestConfig.UserName, TestConfig.UserPassword, TestConfig.DefaultSecurityPackage,
                                                           TestConfig.DefaultRpceAuthenticationLevel, TestConfig.Timeout, server), TestConfig.FailoverTimeout,
                           "Retry BindServer until succeed within timeout span");

            WITNESS_INTERFACE_LIST interfaceList = new WITNESS_INTERFACE_LIST();
            DoUntilSucceed(() =>
            {
                ret = swnClientForInterface.WitnessrGetInterfaceList(out interfaceList);
                BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_SUCCESS, (SwnErrorCode)ret, "WitnessrGetInterfaceList returns with result code = 0x{0:x8}", ret);
                return(SWNTestUtility.VerifyInterfaceList(interfaceList, TestConfig.Platform));
            }, TestConfig.FailoverTimeout, "Retry to call WitnessrGetInterfaceList until succeed within timeout span");

            swnClientForInterface.SwnUnbind(TestConfig.Timeout);

            SWNTestUtility.GetRegisterInterface(interfaceList, out registerInterface);

            SWNTestUtility.CheckVersion(SwnVersion.SWN_VERSION_2, (SwnVersion)registerInterface.Version);
            #endregion

            #region Register SWN witness
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Register SWN witness.");
            DoUntilSucceed(() => SWNTestUtility.BindServer(swnClientForWitness,
                                                           (registerInterface.Flags & (uint)SwnNodeFlagsValue.IPv4) != 0 ? new IPAddress(registerInterface.IPV4) : SWNTestUtility.ConvertIPV6(registerInterface.IPV6),
                                                           TestConfig.DomainName, TestConfig.UserName, TestConfig.UserPassword, TestConfig.DefaultSecurityPackage,
                                                           TestConfig.DefaultRpceAuthenticationLevel, TestConfig.Timeout, server), TestConfig.FailoverTimeout,
                           "Retry BindServer until succeed within timeout span");

            string clientName = Guid.NewGuid().ToString();
            string netName    = SWNTestUtility.GetPrincipleName(TestConfig.DomainName, server);
            string shareName  = TestConfig.ClusteredFileShare;
            WitnessrRegisterExFlagsValue flag = WitnessrRegisterExFlagsValue.WITNESS_REGISTER_NONE;
            if (messageType == SwnMessageType.IP_CHANGE_NOTIFICATION)
            {
                flag = WitnessrRegisterExFlagsValue.WITNESS_REGISTER_IP_NOTIFICATION;
            }

            BaseTestSite.Log.Add(LogEntryKind.Debug, "Register witness:");
            BaseTestSite.Log.Add(LogEntryKind.Debug, "\tNetName: {0}", netName);
            BaseTestSite.Log.Add(LogEntryKind.Debug, "\tIPAddress: {0}", currentAccessIp.ToString());
            BaseTestSite.Log.Add(LogEntryKind.Debug, "\tClient Name: {0}", clientName);

            ret = swnClientForWitness.WitnessrRegisterEx(SwnVersion.SWN_VERSION_2,
                                                         netName,
                                                         shareName,
                                                         currentAccessIp.ToString(),
                                                         clientName,
                                                         flag,
                                                         120,
                                                         out pContext);
            BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_SUCCESS, (SwnErrorCode)ret, "WitnessrRegisterEx returns with result code = 0x{0:x8}", ret);

            BaseTestSite.Assert.IsNotNull(pContext, "Expect pContext is not null.");

            // Reboot witness node (Restart witness service), cause SHARE_MOVE_NOTIFICATION
            callId = swnClientForWitness.WitnessrAsyncNotify(pContext);
            BaseTestSite.Assert.AreNotEqual <uint>(0, callId, "WitnessrAsyncNotify returns callId = {0}", callId);
            RESP_ASYNC_NOTIFY respNotify;

            ret = swnClientForWitness.ExpectWitnessrAsyncNotify(callId, out respNotify);
            BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_SUCCESS, (SwnErrorCode)ret, "WitnessrAsyncNotify returns with result code = 0x{0:x8}", ret);
            SWNTestUtility.PrintNotification(respNotify);
            SWNTestUtility.VerifyClientMoveShareMoveAndIpChange(respNotify, SwnMessageType.SHARE_MOVE_NOTIFICATION, (uint)SwnIPAddrInfoFlags.IPADDR_V4, TestConfig.Platform);
            #endregion

            #region Trigger Notification
            if (messageType == SwnMessageType.IP_CHANGE_NOTIFICATION)
            {
                #region Refresh network adapter on node to trigger IP_CHANGE_NOTIFICATION
                callId = swnClientForWitness.WitnessrAsyncNotify(pContext);
                BaseTestSite.Assert.AreNotEqual <uint>(0, callId, "WitnessrAsyncNotify returns callId = {0}", callId);
                // Refresh an adapter on the node the client is connected, to trigger IP_CHANGE_NOTIFICATION
                BaseTestSite.Log.Add(LogEntryKind.Debug, "Refresh an adapter to trigger IP_CHANGE_NOTIFICATION");
                IPAddress[] addressList      = Dns.GetHostEntry(currentAccessIp).AddressList;
                IPAddress   refreshIpAddress = null;
                foreach (IPAddress ipAddress in addressList)
                {
                    if (ipAddress.ToString() != currentAccessIp.ToString())
                    {
                        refreshIpAddress = ipAddress;
                        break;
                    }
                }

                BaseTestSite.Log.Add(LogEntryKind.TestStep, "Refresh network adapter on node {0} to trigger IP_CHANGE_NOTIFICATION.", refreshIpAddress.ToString());
                sutController.RefreshNetAdapter(refreshIpAddress.ToString(), Dns.GetHostEntry(currentAccessIp).HostName);
                #endregion

                #region Wait for IP_CHANGE_NOTIFICATION
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "Wait for IP_CHANGE_NOTIFICATION.");

                ret = swnClientForWitness.ExpectWitnessrAsyncNotify(callId, out respNotify);
                BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_SUCCESS, (SwnErrorCode)ret, "WitnessrAsyncNotify returns with result code = 0x{0:x8}", ret);
                SWNTestUtility.PrintNotification(respNotify);
                SWNTestUtility.VerifyClientMoveShareMoveAndIpChange(respNotify, SwnMessageType.IP_CHANGE_NOTIFICATION, (uint)(SwnIPAddrInfoFlags.IPADDR_V4 | SwnIPAddrInfoFlags.IPADDR_OFFLINE), TestConfig.Platform);
                // Wait the IP_CHANGE_NOTIFICATION
                callId = swnClientForWitness.WitnessrAsyncNotify(pContext);
                BaseTestSite.Assert.AreNotEqual <uint>(0, callId, "WitnessrAsyncNotify returns callId = {0}", callId);
                ret = swnClientForWitness.ExpectWitnessrAsyncNotify(callId, out respNotify);
                BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_SUCCESS, (SwnErrorCode)ret, "WitnessrAsyncNotify returns with result code = 0x{0:x8}", ret);
                SWNTestUtility.PrintNotification(respNotify);
                // Verify RESP_ASYNC_NOTIFY
                SWNTestUtility.VerifyClientMoveShareMoveAndIpChange(respNotify, SwnMessageType.IP_CHANGE_NOTIFICATION, (uint)(SwnIPAddrInfoFlags.IPADDR_V4 | SwnIPAddrInfoFlags.IPADDR_ONLINE), TestConfig.Platform);
                #endregion
            }
            #endregion

            #region Unregister SWN Witness
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Unregister SWN Witness.");

            ret = swnClientForWitness.WitnessrUnRegister(pContext);
            BaseTestSite.Assert.AreEqual <SwnErrorCode>(SwnErrorCode.ERROR_SUCCESS, (SwnErrorCode)ret, "WitnessrUnRegister returns with result code = 0x{0:x8}", ret);
            pContext = IntPtr.Zero;
            swnClientForWitness.SwnUnbind(TestConfig.Timeout);
            #endregion
        }
Пример #2
0
        /// <summary>
        /// SWN client invoke WitnessrRegisterEx to register for resource state change notifications of a NetName and IPAddress.
        /// </summary>
        /// <param name="Version">The version of the Witness protocol currently in use by the client.</param>
        /// <param name="NetName">Specifies a null-terminated string that specifies the name of the resource for which the client requires notifications.</param>
        /// <param name="ShareName">Specifies a null-terminated string that specifies the name of the share resource for which the client requires notifications.</param>
        /// <param name="IpAddr">Specifies a null-terminated string that specifies the IP address to which the client application connection is established.</param>
        /// <param name="ClientName">Specifies a null-terminated string that is used to identify the Witness client.</param>
        /// <param name="Flags">Specifies the type of Witness registration.</param>
        /// <param name="KeepAliveTimout">Specifies the maximum number of milliseconds for any notification response from the server.</param>
        /// <param name="pContext">A context handle to identifies the client on the server. </param>
        /// <returns>Return zero if success, otherwise return nonzero.</returns>
        public int WitnessrRegisterEx(SwnVersion Version, string NetName, string ShareName, string IpAddr, string ClientName, WitnessrRegisterExFlagsValue Flags, uint KeepAliveTimout, out IntPtr pContext)
        {
            Int3264[] paramList;
            int       retVal = 0;

            SafeIntPtr pNetName    = Marshal.StringToHGlobalUni(NetName);
            SafeIntPtr pShareName  = Marshal.StringToHGlobalUni(ShareName);
            SafeIntPtr pIpAddr     = Marshal.StringToHGlobalUni(IpAddr);
            SafeIntPtr pClientName = Marshal.StringToHGlobalUni(ClientName);

            paramList = new Int3264[] {
                IntPtr.Zero,//out param
                (uint)Version,
                pNetName,
                pShareName,
                pIpAddr,
                pClientName,
                (uint)Flags,
                KeepAliveTimout,
                IntPtr.Zero //return value
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)SWN_OPNUM.WitnessrRegisterEx))
                {
                    pContext = Marshal.ReadIntPtr(outParamList[0]);
                    retVal   = outParamList[paramList.Length - 1].ToInt32();
                }
            }
            finally
            {
                pNetName.Dispose();
                pShareName.Dispose();
                pIpAddr.Dispose();
                pClientName.Dispose();
            }

            return(retVal);
        }
        /// <summary>
        /// SWN client invoke WitnessrRegisterEx to register for resource state change notifications of a NetName and IPAddress.
        /// </summary>
        /// <param name="Version">The version of the Witness protocol currently in use by the client.</param>
        /// <param name="NetName">Specifies a null-terminated string that specifies the name of the resource for which the client requires notifications.</param>
        /// <param name="ShareName">Specifies a null-terminated string that specifies the name of the share resource for which the client requires notifications.</param>
        /// <param name="IpAddr">Specifies a null-terminated string that specifies the IP address to which the client application connection is established.</param>
        /// <param name="ClientName">Specifies a null-terminated string that is used to identify the Witness client.</param>
        /// <param name="Flags">Specifies the type of Witness registration.</param>
        /// <param name="KeepAliveTimout">Specifies the maximum number of milliseconds for any notification response from the server.</param>
        /// <param name="pContext">A context handle to identifies the client on the server. </param>
        /// <returns>Return zero if success, otherwise return nonzero.</returns>
        public int WitnessrRegisterEx(SwnVersion Version, string NetName, string ShareName, string IpAddr, string ClientName, WitnessrRegisterExFlagsValue Flags, uint KeepAliveTimout, out IntPtr pContext)
        {
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pNetName = Marshal.StringToHGlobalUni(NetName);
            SafeIntPtr pShareName = Marshal.StringToHGlobalUni(ShareName);
            SafeIntPtr pIpAddr = Marshal.StringToHGlobalUni(IpAddr);
            SafeIntPtr pClientName = Marshal.StringToHGlobalUni(ClientName);

            paramList = new Int3264[] {
                IntPtr.Zero,//out param
                (uint)Version,
                pNetName,
                pShareName,
                pIpAddr,
                pClientName,
                (uint)Flags,
                KeepAliveTimout,
                IntPtr.Zero //return value
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)SWN_OPNUM.WitnessrRegisterEx))
                {
                    pContext = Marshal.ReadIntPtr(outParamList[0]);
                    retVal = outParamList[paramList.Length - 1].ToInt32();
                }
            }
            finally
            {
                pNetName.Dispose();
                pShareName.Dispose();
                pIpAddr.Dispose();
                pClientName.Dispose();
            }

            return retVal;
        }