/// <summary> /// Verify CLIENT_MOVE_NOTIFICATION/SHARE_MOVE_NOTIFICATION/IP_CHANGE_NOTIFICATION in Asynchronous Notification /// </summary> /// <param name="respNotify">Asynchronous notification</param> /// <param name="expectedMessageType">Expected message type</param> /// <param name="expectedIPAddrInforFlag">Expected flag</param> /// <param name="platform">Platform of SUT</param> public static void VerifyClientMoveShareMoveAndIpChange(RESP_ASYNC_NOTIFY respNotify, SwnMessageType expectedMessageType, uint expectedIPAddrInforFlag, Platform platform) { BaseTestSite.Assert.AreEqual<uint>((uint)expectedMessageType, respNotify.MessageType, "Expect MessageType is set to " + expectedMessageType.ToString()); BaseTestSite.Assert.AreEqual<uint>(1, respNotify.NumberOfMessages, "NumberOfMessages MUST be set to 1."); IPADDR_INFO_LIST IPAddrInfoList; SwnUtility.ParseIPAddrInfoList(respNotify, out IPAddrInfoList); BaseTestSite.Assert.AreEqual<uint>(respNotify.Length, IPAddrInfoList.Length, "Expect Length is the size of the IPADDR_INFO_LIST structure."); BaseTestSite.Assert.AreEqual<uint>(0, IPAddrInfoList.Reserved, "Expect Reserved is 0."); BaseTestSite.Assert.IsTrue(IPAddrInfoList.IPAddrInstances >= 1, "Expect that there is at least one available IPAddress in the IPADDR_INFO structures."); BaseTestSite.Assert.AreEqual<uint>(IPAddrInfoList.IPAddrInstances, (uint)IPAddrInfoList.IPAddrList.Length, "Expect that the length of IPAddrList equals IPAddrInstances ."); for (int i = 0; i < IPAddrInfoList.IPAddrInstances; i++) { /// 2.2.2.1 IPADDR_INFO /// Flags (4 bytes): The Flags field SHOULD<1> be set to a combination of one or more of the following values. /// <1> Section 2.2.2.1: Windows Server 2012 and Windows Server 2012 R2 set the undefined Flags field bits to arbitrary values. if (platform == Platform.NonWindows) { BaseTestSite.Assert.AreEqual<uint>(expectedIPAddrInforFlag, IPAddrInfoList.IPAddrList[i].Flags, "Expect the Flags in IPADDR_INFO structures in the IPAddrList equals " + expectedIPAddrInforFlag.ToString()); } if ((IPAddrInfoList.IPAddrList[i].Flags & (uint)SwnNodeFlagsValue.IPv4) != 0 && IPAddrInfoList.IPAddrList[i].IPV4 == 0) { BaseTestSite.Assert.Fail("The IPV4 {0} in IPAddrInfoList.IPAddrList is invalid.", new IPAddress(IPAddrInfoList.IPAddrList[i].IPV4).ToString()); } else if ((IPAddrInfoList.IPAddrList[i].Flags & (uint)SwnNodeFlagsValue.IPv6) != 0 && IPAddrInfoList.IPAddrList[i].IPV6.All(ip => ip == 0)) { BaseTestSite.Assert.Fail("The IPV6 {0} in IPAddrInfoList.IPAddrList is invalid.", ConvertIPV6(IPAddrInfoList.IPAddrList[i].IPV6).ToString()); } } }
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 }
/// <summary> /// Verify CLIENT_MOVE_NOTIFICATION/SHARE_MOVE_NOTIFICATION/IP_CHANGE_NOTIFICATION in Asynchronous Notification /// </summary> /// <param name="respNotify">Asynchronous notification</param> /// <param name="expectedMessageType">Expected message type</param> /// <param name="expectedIPAddrInforFlag">Expected flag</param> /// <param name="platform">Platform of SUT</param> public static void VerifyClientMoveShareMoveAndIpChange(RESP_ASYNC_NOTIFY respNotify, SwnMessageType expectedMessageType, uint expectedIPAddrInforFlag, Platform platform) { BaseTestSite.Assert.AreEqual <uint>((uint)expectedMessageType, respNotify.MessageType, "Expect MessageType is set to " + expectedMessageType.ToString()); BaseTestSite.Assert.AreEqual <uint>(1, respNotify.NumberOfMessages, "NumberOfMessages MUST be set to 1."); IPADDR_INFO_LIST IPAddrInfoList; SwnUtility.ParseIPAddrInfoList(respNotify, out IPAddrInfoList); BaseTestSite.Assert.AreEqual <uint>(respNotify.Length, IPAddrInfoList.Length, "Expect Length is the size of the IPADDR_INFO_LIST structure."); BaseTestSite.Assert.AreEqual <uint>(0, IPAddrInfoList.Reserved, "Expect Reserved is 0."); BaseTestSite.Assert.IsTrue(IPAddrInfoList.IPAddrInstances >= 1, "Expect that there is at least one available IPAddress in the IPADDR_INFO structures."); BaseTestSite.Assert.AreEqual <uint>(IPAddrInfoList.IPAddrInstances, (uint)IPAddrInfoList.IPAddrList.Length, "Expect that the length of IPAddrList equals IPAddrInstances ."); for (int i = 0; i < IPAddrInfoList.IPAddrInstances; i++) { /// 2.2.2.1 IPADDR_INFO /// Flags (4 bytes): The Flags field SHOULD<1> be set to a combination of one or more of the following values. /// <1> Section 2.2.2.1: Windows Server 2012 and Windows Server 2012 R2 set the undefined Flags field bits to arbitrary values. if (platform == Platform.NonWindows) { BaseTestSite.Assert.AreEqual <uint>(expectedIPAddrInforFlag, IPAddrInfoList.IPAddrList[i].Flags, "Expect the Flags in IPADDR_INFO structures in the IPAddrList equals " + expectedIPAddrInforFlag.ToString()); } if ((IPAddrInfoList.IPAddrList[i].Flags & (uint)SwnNodeFlagsValue.IPv4) != 0 && IPAddrInfoList.IPAddrList[i].IPV4 == 0) { BaseTestSite.Assert.Fail("The IPV4 {0} in IPAddrInfoList.IPAddrList is invalid.", new IPAddress(IPAddrInfoList.IPAddrList[i].IPV4).ToString()); } else if ((IPAddrInfoList.IPAddrList[i].Flags & (uint)SwnNodeFlagsValue.IPv6) != 0 && IPAddrInfoList.IPAddrList[i].IPV6.All(ip => ip == 0)) { BaseTestSite.Assert.Fail("The IPV6 {0} in IPAddrInfoList.IPAddrList is invalid.", ConvertIPV6(IPAddrInfoList.IPAddrList[i].IPV6).ToString()); } } }
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 }