public bool CreateProfile(string profile, string profileName) { try { using (Wlan wlanApi = new Wlan()) { testLogger.LogTrace("CreateProfile"); var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); if (NetworkInterfaceDataPathTests.CheckWlanInterfaceCount(wlanApi) == false) { return(false); } var wlanInterface = wlanInterfaceList[0]; testLogger.LogComment("Creating Profile {0}", profileName); wlanApi.CreateProfile(wlanInterface.Id, profile); return(true); } } catch (Exception error) { testLogger.LogError("Error encountered while Creating the Wlan Profile {0}", profileName); testLogger.LogError(error.ToString()); return(false); } }
public bool DisconnectNetwork() { testLogger.LogComment("Disconnecting from WLAN"); try { using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); if (NetworkInterfaceDataPathTests.CheckWlanInterfaceCount(wlanApi) == false) { return(false); } var wlanInterface = wlanInterfaceList[0]; if (wlanInterface.State == WLAN_INTERFACE_STATE.wlan_interface_state_connected) { testLogger.LogComment("Disconnecting from WLAN network {0}", wlanInterface.Ssid); wlanApi.Disconnect(wlanInterface.Id, new TimeSpan(0, 0, 10)); } return(true); } } catch (Exception error) { testLogger.LogError("Error encountered while Disconnecting from the WLAN Network"); testLogger.LogError(error.ToString()); return(false); } }
public string FindLocalLanAddress(bool ipv6, Guid interfaceId) { testLogger.LogTrace("FindLocalLanAddress"); string returnAddress = NetworkInterfaceDataPathTests.GetLanEndpoint(ipv6, interfaceId); testLogger.LogComment("FindLocalLanAddress: {0}", returnAddress); testLogger.LogTrace("FindLocalLanAddress Length: {0}", returnAddress.Length); return(returnAddress); }
public bool ConnectToNetwork(string ssid) { try { using (Wlan wlanApi = new Wlan()) { testLogger.LogComment("ConnectToNetwork"); var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); if (NetworkInterfaceDataPathTests.CheckWlanInterfaceCount(wlanApi) == false) { return(false); } var wlanInterface = wlanInterfaceList[0]; bool localConnectionNeeded = true; if (wlanInterface.State == WLAN_INTERFACE_STATE.wlan_interface_state_connected) { if (String.Compare(ssid, wlanInterface.Ssid, StringComparison.OrdinalIgnoreCase) == 0) { testLogger.LogComment("We already connected to the correct network."); localConnectionNeeded = false; } else { testLogger.LogComment("We already connected a different network. Disconnecting."); wlanApi.Disconnect(wlanInterface.Id, new TimeSpan(0, 0, 10)); Wlan.Sleep(1000); } } if (localConnectionNeeded) { testLogger.LogComment("Connecting to SSID {0}", ssid); wlanApi.TryScan(wlanInterface.Id, false, new TimeSpan(0, 0, 10)); wlanApi.ProfileConnect(wlanInterface.Id, ssid, new TimeSpan(0, 0, 30)); testLogger.LogComment("Connection Completed {0}", ssid); testLogger.LogComment("Waiting for DHCP to be stable"); Microsoft.Test.Networking.Kit.Helpers.WaitForWlanConnectivity(wlanInterface.Id, 1000 * 15, testLogger); } return(true); } } catch (Exception error) { testLogger.LogError("Error encountered while Connecting to the Wlan Profile {0}", ssid); testLogger.LogError(error.ToString()); return(false); } }
private void SendThread(object obj) { CancellationToken token = (CancellationToken)obj; IntPtr socket = IntPtr.Zero; try { testLogger.LogComment("TCP Sends from {0}:{1} to {2}:{3}", localAddress, localPort, remoteAddress, remotePort); socket = sockets.CreateTcpSocket(localAddress, localPort, ipv6Mode); sockets.Connect(socket, remoteAddress, remotePort, ipv6Mode); testLogger.LogComment("Connected to TCP Server at {0}:{1}", remoteAddress, remotePort); Byte[] sendData; while (!token.IsCancellationRequested) { sendData = NetworkInterfaceDataPathTests.GeneratePayload(1000); testLogger.LogTrace("TcpSender[{0}] Sending Data", this.identifier); sockets.Send(socket, sendData); UnitsTransfered += sendData.Length; Wlan.Sleep(NetworkInterfaceDataPathTests.RandomWaitTime()); DateTime nextLogTime = DateTime.Now; if (DateTime.Now > nextLogTime) { testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Sending TCP Data to {0}:{1}. Bytes Sent {2}", remoteAddress, remotePort, UnitsTransfered)); nextLogTime = DateTime.Now.Add(logInterval); } testLogger.LogTrace("TcpSender[{0}] Total Bytes Sent: {1}", this.identifier, UnitsTransfered); } testLogger.LogComment("TCP Send Completed from {0}:{1} to {2}:{3} Bytes Count = {4}", localAddress, localPort, remoteAddress, remotePort, UnitsTransfered); } catch (Exception error) { testLogger.LogError(string.Format(CultureInfo.InvariantCulture, "Error when sending TCP Data from {0}:{1} to {2}:{3} : {4}", localAddress, localPort, remoteAddress, remotePort, error.ToString())); throw; } finally { if (socket != IntPtr.Zero) { testLogger.LogTrace("TcpSender[{0}] Closing Send Socket", this.identifier); sockets.CloseSocket(socket); } } }
public void Configure(TestMode testMode, Guid localInterfaceGuid, string address, bool ipv6, UInt16 port) { this.ipv6Mode = ipv6; localPort = port; if (testMode == TestMode.Wlan) { localAddress = NetworkInterfaceDataPathTests.GetWirelessEndpoint(ipv6Mode); } else { localAddress = NetworkInterfaceDataPathTests.GetLanEndpoint(ipv6Mode, localInterfaceGuid); } this.identifier = String.Format(CultureInfo.InvariantCulture, "{0}:{1}", localAddress, localPort); testLogger.LogComment("MulticastReceiver[{0}] local address", this.identifier); testLogger.LogTrace("Creating Multicast Receive Socket"); if (ipv6Mode) { if (testMode == TestMode.Wlan) { using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); if (wlanInterfaceList.Count < 1) { throw new TestConfigException("No WLAN Interfaces were discovered. Ensure that WLAN interfaces are enabled, discoverable, and operational."); } var wlanInterface = wlanInterfaceList[0]; UInt32 wlanInterfaceIndex = NetworkInterfaceDataPathTests.GetNetworkIndex(wlanInterface.Id); listenSocket = sockets.CreateMulticastSocket(localAddress, localPort, address, port, wlanInterfaceIndex); } } else { UInt32 lanInterfaceIndex = NetworkInterfaceDataPathTests.GetNetworkIndex(localInterfaceGuid); listenSocket = sockets.CreateMulticastSocket(localAddress, localPort, address, port, lanInterfaceIndex); } } else { listenSocket = sockets.CreateMulticastSocket(localAddress, localPort, address, port); } }
private void SendThread(object obj) { CancellationToken token = (CancellationToken)obj; IntPtr socket = IntPtr.Zero; try { testLogger.LogComment("Broadcast Sends from {0}:{1} to {2}:{3}", localAddress, localPort, remoteAddress, remotePort); socket = sockets.CreateBroadcastSocket(localAddress, localPort); UnitsTransfered++; Byte[] sendData; while (!token.IsCancellationRequested) { sendData = NetworkInterfaceDataPathTests.GeneratePayload(100); testLogger.LogTrace("BroadcastSender[{0}] Sending Packet", this.identifier); sockets.SendTo(socket, sendData, remoteAddress, remotePort, false); Wlan.Sleep(NetworkInterfaceDataPathTests.RandomWaitTime()); UnitsTransfered++; DateTime nextLogTime = DateTime.Now; if (DateTime.Now > nextLogTime) { testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Sending Broadcast Data to {0}:{1}. Packets Sent {2}", remoteAddress, remotePort, UnitsTransfered)); nextLogTime = DateTime.Now.Add(logInterval); } testLogger.LogTrace("BroadcastSender[{0}] Packets Sent: {1}", this.identifier, UnitsTransfered); } testLogger.LogComment("Broadcast Send Completed from {0}:{1} to {2}:{3}. Packet Count = {4}", localAddress, localPort, remoteAddress, remotePort, UnitsTransfered); } catch (Exception error) { testLogger.LogError(error.ToString()); throw; } finally { if (socket != IntPtr.Zero) { testLogger.LogTrace("BroadcastSender[{0}] Closing Send Socket", this.identifier); sockets.CloseSocket(socket); } } }
public void Configure(TestMode testMode, Guid localInterfaceGuid, string address, bool ipv6, UInt16 port) { this.ipv6Mode = ipv6; localPort = port; if (testMode == TestMode.Wlan) { localAddress = NetworkInterfaceDataPathTests.GetWirelessEndpoint(ipv6Mode); } else { localAddress = NetworkInterfaceDataPathTests.GetLanEndpoint(ipv6Mode, localInterfaceGuid); } this.identifier = String.Format(CultureInfo.InvariantCulture, "{0}:{1}", localAddress, localPort); testLogger.LogComment("BroadcastReceiver[{0}] local address", this.identifier); listenSocket = sockets.CreateUdpSocket(localAddress, localPort, ipv6Mode); }
public void Configure(TestMode testMode, Guid localInterfaceGuid, string address, bool ipv6, UInt16 port) { this.ipv6Mode = ipv6; this.remoteAddress = address; this.remotePort = port; localPort = port; if (testMode == TestMode.Wlan) { localAddress = NetworkInterfaceDataPathTests.GetWirelessEndpoint(ipv6Mode); } else { localAddress = NetworkInterfaceDataPathTests.GetLanEndpoint(ipv6Mode, localInterfaceGuid); } this.identifier = String.Format(CultureInfo.InvariantCulture, "{0}:{1}", localAddress, localPort); testLogger.LogComment("BroadcastSender[{0}] Remote {1}:{2}", this.identifier, this.remoteAddress, this.remotePort); }
private void SendThread(object obj) { CancellationToken token = (CancellationToken)obj; IntPtr socket = IntPtr.Zero; try { testLogger.LogComment("Multicast Sends from {0}:{1} to {2}:{3}", localAddress, localPort, remoteAddress, remotePort); if (ipv6Mode) { if (testMode == TestMode.Wlan) { using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); if (wlanInterfaceList.Count < 1) { throw new TestConfigException("No WLAN Interfaces were discovered. Ensure that WLAN interfaces are enabled, discoverable, and operational."); } var wlanInterface = wlanInterfaceList[0]; UInt32 wlanInterfaceIndex = NetworkInterfaceDataPathTests.GetNetworkIndex(wlanInterface.Id); socket = sockets.CreateMulticastSocket(localAddress, localPort, remoteAddress, remotePort, wlanInterfaceIndex); } } else { UInt32 lanInterfaceIndex = NetworkInterfaceDataPathTests.GetNetworkIndex(localInterfaceGuid); socket = sockets.CreateMulticastSocket(localAddress, localPort, remoteAddress, remotePort, lanInterfaceIndex); } } else { socket = sockets.CreateMulticastSocket(localAddress, localPort, remoteAddress, remotePort); } Byte[] sendData; while (!token.IsCancellationRequested) { sendData = NetworkInterfaceDataPathTests.GeneratePayload(100); testLogger.LogTrace("MulticastSender[{0}] Sending Packet", this.identifier); sockets.SendTo(socket, sendData, remoteAddress, remotePort, ipv6Mode); UnitsTransfered++; Wlan.Sleep(NetworkInterfaceDataPathTests.RandomWaitTime()); DateTime nextLogTime = DateTime.Now; if (DateTime.Now > nextLogTime) { testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Sending Multicast Data to {0}:{1}. Packets Sent {2}", remoteAddress, remotePort, UnitsTransfered)); nextLogTime = DateTime.Now.Add(logInterval); } testLogger.LogTrace("MulticastSender[{0}] Packets Sent {1}", this.identifier, UnitsTransfered); } testLogger.LogComment("Multicast Send Completed from {0}:{1} to {2}:{3}. Packet Count = {4}", localAddress, localPort, remoteAddress, remotePort, UnitsTransfered); } catch (Exception error) { testLogger.LogError(error.ToString()); throw; } finally { if (socket != IntPtr.Zero) { testLogger.LogTrace("MulticastSender[{0}] Closing Send Socket", this.identifier); sockets.CloseSocket(socket); } } }