/// <summary> /// Parse IPADDR_INFO_LIST from RESP_ASYNC_NOTIFY. /// </summary> /// <param name="respNotify">A pointer to a PRESP_ASYNC_NOTIFY structure, as specified in section 2.2.1.7.</param> /// <param name="IPAddrInfoList">IPADDR_INFO_LIST list.</param> public static void ParseIPAddrInfoList(RESP_ASYNC_NOTIFY respNotify, out IPADDR_INFO_LIST IPAddrInfoList) { IPAddrInfoList = new IPADDR_INFO_LIST(); IPAddrInfoList.Length = BitConverter.ToUInt32(respNotify.MessageBuffer, 0); IPAddrInfoList.Reserved = BitConverter.ToUInt32(respNotify.MessageBuffer, sizeof(int)); IPAddrInfoList.IPAddrInstances = BitConverter.ToUInt32(respNotify.MessageBuffer, 2 * sizeof(int)); IPAddrInfoList.IPAddrList = new IPADDR_INFO[IPAddrInfoList.IPAddrInstances]; int len = 3 * sizeof(int); for (int i = 0; i < IPAddrInfoList.IPAddrInstances; i++) { IPAddrInfoList.IPAddrList[i].Flags = BitConverter.ToUInt32(respNotify.MessageBuffer, len); if ((IPAddrInfoList.IPAddrList[i].Flags & (uint)SwnIPAddrInfoFlags.IPADDR_V4) != 0) { IPAddrInfoList.IPAddrList[i].IPV4 = BitConverter.ToUInt32(respNotify.MessageBuffer, len + sizeof(int)); } IPAddrInfoList.IPAddrList[i].IPV6 = new ushort[8]; if ((IPAddrInfoList.IPAddrList[i].Flags & (uint)SwnIPAddrInfoFlags.IPADDR_V6) != 0) { Array.Copy(respNotify.MessageBuffer, len + 2 * sizeof(int), IPAddrInfoList.IPAddrList[i].IPV6, 0, 8); } len += 2 * sizeof(int) + 8 * sizeof(ushort); } }
/// <summary> /// Parse RESOURCE_CHANGE from RESP_ASYNC_NOTIFY. /// </summary> /// <param name="respNotify">A pointer to a PRESP_ASYNC_NOTIFY structure, as specified in section 2.2.1.7.</param> /// <param name="resourceChangeList">RESOURCE_CHANGE list.</param> public static void ParseResourceChange(RESP_ASYNC_NOTIFY respNotify, out RESOURCE_CHANGE[] resourceChangeList) { resourceChangeList = new RESOURCE_CHANGE[respNotify.NumberOfMessages]; int len = 0; for (int i = 0; i < respNotify.NumberOfMessages; i++) { resourceChangeList[i] = new RESOURCE_CHANGE(); resourceChangeList[i].Length = BitConverter.ToUInt32(respNotify.MessageBuffer, len); resourceChangeList[i].ChangeType = BitConverter.ToUInt32(respNotify.MessageBuffer, len + sizeof(int)); resourceChangeList[i].ResourceName = Encoding.Unicode.GetString(respNotify.MessageBuffer, len + 2 * sizeof(int), (int)(resourceChangeList[i].Length - 2 * sizeof(int))); len += (int)resourceChangeList[i].Length; } }
/// <summary> /// Parse RESOURCE_CHANGE from RESP_ASYNC_NOTIFY. /// </summary> /// <param name="respNotify">A pointer to a PRESP_ASYNC_NOTIFY structure, as specified in section 2.2.1.7.</param> /// <param name="resourceChangeList">RESOURCE_CHANGE list.</param> public static void ParseResourceChange(RESP_ASYNC_NOTIFY respNotify, out RESOURCE_CHANGE[] resourceChangeList) { resourceChangeList = new RESOURCE_CHANGE[respNotify.NumberOfMessages]; int len = 0; for (int i = 0; i < respNotify.NumberOfMessages; i++) { resourceChangeList[i] = new RESOURCE_CHANGE(); resourceChangeList[i].Length = BitConverter.ToUInt32(respNotify.MessageBuffer, len); resourceChangeList[i].ChangeType = BitConverter.ToUInt32(respNotify.MessageBuffer, len + sizeof(int)); resourceChangeList[i].ResourceName = Encoding.Unicode.GetString(respNotify.MessageBuffer, len + 2 * sizeof(int), (int)(resourceChangeList[i].Length - 2 * sizeof(int))); len += (int)resourceChangeList[i].Length; } }
/// <summary> /// SWN client invoke WitnessrAsyncNotify method to post a message on the server; this message is completed when there are no longer any notifications which are required to be communicated with the client. /// </summary> /// <param name="callId">The identifier of this async call.</param> /// <param name="NotifyResp">Structure contains the resource change notification from server.</param> /// <returns>Return zero if success, otherwise return nonzero.</returns> public int ExpectWitnessrAsyncNotify(uint callId, out RESP_ASYNC_NOTIFY NotifyResp) { int retVal = 0; using (RpceInt3264Collection outParamList = RpceAsyncCallExpect(callId)) { retVal = outParamList[2].ToInt32(); if (retVal == (int)SwnErrorCode.ERROR_SUCCESS) { NotifyResp = TypeMarshal.ToStruct <RESP_ASYNC_NOTIFY>(Marshal.ReadIntPtr(outParamList[1])); } else { NotifyResp = new RESP_ASYNC_NOTIFY(); } } return(retVal); }
/// <summary> /// SWN client invoke WitnessrAsyncNotify method to post a message on the server; this message is completed when there are no longer any notifications which are required to be communicated with the client. /// </summary> /// <param name="callId">The identifier of this async call.</param> /// <param name="NotifyResp">Structure contains the resource change notification from server.</param> /// <returns>Return zero if success, otherwise return nonzero.</returns> public int ExpectWitnessrAsyncNotify(uint callId, out RESP_ASYNC_NOTIFY NotifyResp) { int retVal = 0; using (RpceInt3264Collection outParamList = RpceAsyncCallExpect(callId)) { retVal = outParamList[2].ToInt32(); if (retVal == (int)SwnErrorCode.ERROR_SUCCESS) { NotifyResp = TypeMarshal.ToStruct<RESP_ASYNC_NOTIFY>(Marshal.ReadIntPtr(outParamList[1])); } else { NotifyResp = new RESP_ASYNC_NOTIFY(); } } return retVal; }
/// <summary> /// Parse IPADDR_INFO_LIST from RESP_ASYNC_NOTIFY. /// </summary> /// <param name="respNotify">A pointer to a PRESP_ASYNC_NOTIFY structure, as specified in section 2.2.1.7.</param> /// <param name="IPAddrInfoList">IPADDR_INFO_LIST list.</param> public static void ParseIPAddrInfoList(RESP_ASYNC_NOTIFY respNotify, out IPADDR_INFO_LIST IPAddrInfoList) { IPAddrInfoList = new IPADDR_INFO_LIST(); IPAddrInfoList.Length = BitConverter.ToUInt32(respNotify.MessageBuffer, 0); IPAddrInfoList.Reserved = BitConverter.ToUInt32(respNotify.MessageBuffer, sizeof(int)); IPAddrInfoList.IPAddrInstances = BitConverter.ToUInt32(respNotify.MessageBuffer, 2 * sizeof(int)); IPAddrInfoList.IPAddrList = new IPADDR_INFO[IPAddrInfoList.IPAddrInstances]; int len = 3 * sizeof(int); for (int i = 0; i < IPAddrInfoList.IPAddrInstances; i++) { IPAddrInfoList.IPAddrList[i].Flags = BitConverter.ToUInt32(respNotify.MessageBuffer, len); if ((IPAddrInfoList.IPAddrList[i].Flags & (uint)SwnIPAddrInfoFlags.IPADDR_V4) != 0) { IPAddrInfoList.IPAddrList[i].IPV4 = BitConverter.ToUInt32(respNotify.MessageBuffer, len + sizeof(int)); } IPAddrInfoList.IPAddrList[i].IPV6 = new ushort[8]; if ((IPAddrInfoList.IPAddrList[i].Flags & (uint)SwnIPAddrInfoFlags.IPADDR_V6) != 0) { Array.Copy(respNotify.MessageBuffer, len + 2 * sizeof(int), IPAddrInfoList.IPAddrList[i].IPV6, 0, 8); } len += 2 * sizeof(int) + 8 * sizeof(ushort); } }
/// <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; } }
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); } }