static void PrintNotification(RESP_ASYNC_NOTIFY respNotify) { if ((SwnMessageType)respNotify.MessageType == SwnMessageType.RESOURCE_CHANGE_NOTIFICATION) { Console.WriteLine("MessageType: SWN_SERVER_MESSAGE_RESOURCE_CHANGE_NOTIFICATION"); RESOURCE_CHANGE[] resourceChangeList; SwnUtility.ParseResourceChange(respNotify, out resourceChangeList); foreach (var res in resourceChangeList) { Console.WriteLine("Resource name: {0}", res.ResourceName); switch ((SwnResourceChangeType)res.ChangeType) { case SwnResourceChangeType.RESOURCE_STATE_UNKNOWN: Console.WriteLine("Change type: RESOURCE_STATE_UNKNOWN"); break; case SwnResourceChangeType.RESOURCE_STATE_AVAILABLE: Console.WriteLine("Change type: RESOURCE_STATE_AVAILABLE"); break; case SwnResourceChangeType.RESOURCE_STATE_UNAVAILABLE: Console.WriteLine("Change type: SWN_RESOURCE_STATE_UNAVAILABLE"); break; default: Console.WriteLine("Change type: Unknown type {0}", res.ChangeType); break; } } } else if ((SwnMessageType)respNotify.MessageType == SwnMessageType.RESOURCE_MOVE_NOTIFICATION) { Console.WriteLine("MessageType: SWN_SERVER_MESSAGE_RESOURCE_MOVE_NOTIFICATION"); MOVE_REQUEST moveRequest; SwnUtility.ParseMoveRequest(respNotify, out moveRequest); foreach (var ip in moveRequest.IPAddrList) { Console.WriteLine("---------------------------------"); if (((uint)SwnIPAddrType.MOVE_DST_IPADDR_V4 & ip.Flags) != 0) { Console.WriteLine("IPAddr V4: {0}", ip.IPV4); } if (((uint)SwnIPAddrType.MOVE_DST_IPADDR_V6 & ip.Flags) != 0) { Console.WriteLine("IPAddr V6: {0}", ip.IPV6); } } } else { Console.WriteLine("MessageType: Unknown type: {0}", respNotify.MessageType); } }
/// <summary> /// Verify RESOURCE_CHANGE_NOTIFICATION in Asynchronous Notification /// </summary> /// <param name="respNotify">Asynchronous notification</param> /// <param name="changeType">State change of the resource</param> public static void VerifyResourceChange(RESP_ASYNC_NOTIFY respNotify, SwnResourceChangeType changeType) { BaseTestSite.Assert.AreEqual <uint>((uint)SwnMessageType.RESOURCE_CHANGE_NOTIFICATION, respNotify.MessageType, "Expect MessageType is set to RESOURCE_CHANGE_NOTIFICATION"); RESOURCE_CHANGE[] resourceChangeList; SwnUtility.ParseResourceChange(respNotify, out resourceChangeList); BaseTestSite.Assert.AreEqual <uint>(0x00000001, respNotify.NumberOfMessages, "Expect NumberOfMessages is set to 1."); BaseTestSite.Assert.AreEqual <uint>((uint)changeType, resourceChangeList[0].ChangeType, "Expect ChangeType is set to {0}.", changeType); }
/// <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()); } } }
/// <summary> /// Print RESP_ASYNC_NOTIFY /// </summary> /// <param name="respNotify">Asynchronous notification</param> public static void PrintNotification(RESP_ASYNC_NOTIFY respNotify) { BaseTestSite.Log.Add(LogEntryKind.Debug, "Receive asynchronous notification"); switch ((SwnMessageType)respNotify.MessageType) { case SwnMessageType.RESOURCE_CHANGE_NOTIFICATION: { RESOURCE_CHANGE[] resourceChangeList; SwnUtility.ParseResourceChange(respNotify, out resourceChangeList); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tRESOURCE_CHANGE"); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tcount: {0}", resourceChangeList.Length); foreach (var res in resourceChangeList) { BaseTestSite.Log.Add(LogEntryKind.Debug, "\t\tResource name: {0}", res.ResourceName.Substring(0, res.ResourceName.Length - 1)); switch ((SwnResourceChangeType)res.ChangeType) { case SwnResourceChangeType.RESOURCE_STATE_UNKNOWN: BaseTestSite.Log.Add(LogEntryKind.Debug, "\t\tChange type: RESOURCE_STATE_UNKNOWN"); break; case SwnResourceChangeType.RESOURCE_STATE_AVAILABLE: BaseTestSite.Log.Add(LogEntryKind.Debug, "\t\tChange type: RESOURCE_STATE_AVAILABLE"); break; case SwnResourceChangeType.RESOURCE_STATE_UNAVAILABLE: BaseTestSite.Log.Add(LogEntryKind.Debug, "\t\tChange type: RESOURCE_STATE_UNAVAILABLE"); break; default: BaseTestSite.Log.Add(LogEntryKind.Debug, "\t\tChange type: Unknown type {0}", res.ChangeType); break; } } } break; case SwnMessageType.CLIENT_MOVE_NOTIFICATION: { IPADDR_INFO_LIST IPAddrInfoList; SwnUtility.ParseIPAddrInfoList(respNotify, out IPAddrInfoList); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tCLIENT_MOVE"); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tReserved: {0}", IPAddrInfoList.Reserved); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tIP address count: {0}", IPAddrInfoList.IPAddrInstances); foreach (var ip in IPAddrInfoList.IPAddrList) { BaseTestSite.Log.Add(LogEntryKind.Debug, "\tFlags: {0}", ip.Flags); if (((uint)SwnIPAddrInfoFlags.IPADDR_V4 & ip.Flags) != 0) { BaseTestSite.Log.Add(LogEntryKind.Debug, "\tIPAddr V4: {0}", (new IPAddress(ip.IPV4)).ToString()); } if (((uint)SwnIPAddrInfoFlags.IPADDR_V6 & ip.Flags) != 0) { BaseTestSite.Log.Add(LogEntryKind.Debug, "\tIPAddr V6: {0}", ConvertIPV6(ip.IPV6).ToString()); } } } break; case SwnMessageType.SHARE_MOVE_NOTIFICATION: { IPADDR_INFO_LIST IPAddrInfoList; SwnUtility.ParseIPAddrInfoList(respNotify, out IPAddrInfoList); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tSHARE_MOVE"); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tReserved: {0}", IPAddrInfoList.Reserved); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tIP address count: {0}", IPAddrInfoList.IPAddrInstances); foreach (var ip in IPAddrInfoList.IPAddrList) { BaseTestSite.Log.Add(LogEntryKind.Debug, "\tFlags: {0}", ip.Flags); if (((uint)SwnIPAddrInfoFlags.IPADDR_V4 & ip.Flags) != 0) { BaseTestSite.Log.Add(LogEntryKind.Debug, "\tIPAddr V4: {0}", (new IPAddress(ip.IPV4)).ToString()); } if (((uint)SwnIPAddrInfoFlags.IPADDR_V6 & ip.Flags) != 0) { BaseTestSite.Log.Add(LogEntryKind.Debug, "\tIPAddr V6: {0}", ConvertIPV6(ip.IPV6).ToString()); } } } break; case SwnMessageType.IP_CHANGE_NOTIFICATION: { IPADDR_INFO_LIST IPAddrInfoList; SwnUtility.ParseIPAddrInfoList(respNotify, out IPAddrInfoList); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tIP_CHANGE"); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tReserved: {0}", IPAddrInfoList.Reserved); BaseTestSite.Log.Add(LogEntryKind.Debug, "\tIP address count: {0}", IPAddrInfoList.IPAddrInstances); foreach (var ip in IPAddrInfoList.IPAddrList) { BaseTestSite.Log.Add(LogEntryKind.Debug, "\tFlags: {0}", ip.Flags); if (((uint)SwnIPAddrInfoFlags.IPADDR_V4 & ip.Flags) != 0) { BaseTestSite.Log.Add(LogEntryKind.Debug, "\tIPAddr V4: {0}", (new IPAddress(ip.IPV4)).ToString()); } if (((uint)SwnIPAddrInfoFlags.IPADDR_V6 & ip.Flags) != 0) { BaseTestSite.Log.Add(LogEntryKind.Debug, "\tIPAddr V6: {0}", ConvertIPV6(ip.IPV6).ToString()); } } } break; default: BaseTestSite.Assert.Fail("\t\tMessage type: Unknown type {0}", respNotify.MessageType); break; } }