public bool ConnectToEchoServer() { CloseEchoClient(); Log("SetupRoutersAndProfilesIfNeeded: Restart echo services to free stale connections"); AC.StartEchoServer(EchoPort, EchoByteStream, 5); Log("ConnectToEchoServer - Extracting Local IP Address of Interface"); string localIPAddress = null; try { localIPAddress = Helpers.GetIPAddressOfTestAdapter(TestInterface.Id); } catch (Exception e) { LogError("Failed to extract the IPV4 address associated with the test adapter. " + e.Message); return(false); } Log("ConnectToEchoServer - Creating an echo client"); echoClient = new TCPEchoClient(localIPAddress, RoamingConfiguration.ServiceAPChannelAddress, EchoPort, EchoByteStream); Log("ConnectToEchoServer - Connecting echo client to EchoServer"); try { echoClient.Connect(); } catch (Exception e) { LogError("Failed to connect to the tcp server:" + RoamingConfiguration.ServiceAPChannelAddress + " - Port: " + EchoPort + " " + e.Message); return(false); } return(true); }
private bool RunIntegrityCheck() { testLogger.LogComment("Running integrity check"); UInt16 port = 7777; UInt16 streamBytes = Convert.ToUInt16(random.Next(10, 2000)); nextIntegrityCheckTime = DateTime.Now.Add(integrityCheckInterval); using (ApConfigClient apConfigClient = new ApConfigClient(WlanStress.APServer)) { testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "WlanStress.APServer: {0}", WlanStress.APServer)); int retries = 3; bool connected = false; while (retries > 0) { retries--; testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Attempting to connect to AP machine. Retries remaining: {0}", retries)); bool connect = apConfigClient.Connect(); if (connect) { testLogger.LogComment("Connection to AP Server Succeeded"); connected = true; break; } else { testLogger.LogComment("Connection AP Server failed"); Wlan.Sleep(10000); } } if (connected == false) { testLogger.LogError("Giving up connecting to AP machine"); return(false); } apConfigClient.StartEchoServer(port, streamBytes, 1); ConnectForIntegrityCheck(apConfigClient, port, streamBytes); try { using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); var wlanInterface = wlanInterfaceList[0]; using (Win32Sockets win32Sockets = new Win32Sockets()) { string localAddress = win32Sockets.FindIpAddress(wlanInterface.Id); testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "IPAddress: {0}", localAddress)); using (TCPEchoClient echoClient = new TCPEchoClient(localAddress, ServiceAPChannelAddress, port, streamBytes)) { echoClient.Connect(); echoClient.PerformEcho(); bool result = echoClient.IsResponseBufferValid(); testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Echo Client Success: {0}", result)); return(result); } } } } catch (Exception error) { testLogger.LogComment("TlukeTest: Exception hit"); testLogger.LogError(string.Format(CultureInfo.InvariantCulture, "Error While trying data path: {0}", error.ToString())); return(false); } finally { testLogger.LogComment("Cleaning Up Each Server"); apConfigClient.StopEchoServer(); using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); var wlanInterface = wlanInterfaceList[0]; if (wlanInterface.State == WLAN_INTERFACE_STATE.wlan_interface_state_connected) { wlanApi.Disconnect(wlanInterface.Id, DisconnectWait); } } } } }