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); } }
public bool bValidateGHZRadioAssociation(int APIndex, string expectedBssid) { for (int i = 0; i < 4; i++) { string associatedWith = Helpers.GetBSSID(Api, TestInterface); if (associatedWith == expectedBssid) { Log("bValidateGHZRadioAssociation Associated with Radio " + APIndex + " having bssid " + expectedBssid + " as expected"); return(true); } Log("bValidateGHZRadioAssociation Not associated with Radio " + APIndex + " having bssid " + expectedBssid + ". Assoicated with" + associatedWith + ". Will Retry to account for propogation issues"); Wlan.Sleep(500); } LogError("bValidateGHZRadioAssociation Giving up. Not associated with Radio " + APIndex + " having bssid " + expectedBssid); 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); } } }
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 override void Run(string profileName1, string profileName2) { DateTime endTime = DateTime.Now.Add(new TimeSpan(0, 5, 0)); TimeSpan waiterTimeout = new TimeSpan(0, 0, 10); 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]; while (DateTime.Now < endTime) { if (Random.Next(0, 2) == 1) { // Slow Scan testLogger.LogComment("Slow Scan"); int iterations = Random.Next(10); for (int toggleLooper = 0; toggleLooper < iterations; toggleLooper++) { testLogger.LogComment("Scanning..."); wlanApi.TryScan(wlanInterface.Id, false, WlanStress.ScanWait); testLogger.LogComment("Scanning...Complete"); SlowScans++; } } else { // Fast Scan testLogger.LogComment("Fast Scan"); int iterations = Random.Next(10); for (int toggleLooper = 0; toggleLooper < iterations; toggleLooper++) { testLogger.LogComment("Start Fast Scan"); wlanApi.TryScan(wlanInterface.Id, false); FastScans++; } testLogger.LogComment("Sleeping for a few seconds to allow the driver to calm down"); Wlan.Sleep(10000); } } } }
private void DisconnectAndDeleteProfile(Wlan wlanApi) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); if (wlanInterfaceList[0].State == WLAN_INTERFACE_STATE.wlan_interface_state_connected) { testLogger.LogComment("Disconnecting from AP"); wlanApi.Disconnect(wlanInterfaceList[0].Id); Wlan.Sleep(5000); } try { testLogger.LogComment("Deleting Profile"); wlanApi.DeleteProfile(wlanInterfaceList[0].Id, dot11wSSID); } catch (System.Runtime.InteropServices.COMException) { // The profile was not present to delete } }
private void SleepWhileConnected(DateTime endTime, string profileName1) { testLogger.LogComment("SleepWhileConnected"); 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) { testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Connecting to {0}", profileName1)); wlanApi.ProfileConnect(wlanInterface.Id, profileName1, WlanStress.ConnectWait); } while (DateTime.Now < endTime) { int sleepTime = Random.Next(1, 60); testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Sleeping for {0} seconds", sleepTime)); WakeHelper.StaticD2Sleep(new TimeSpan(0, 0, sleepTime)); testLogger.LogComment("Verify we are still connected"); connectedAfterSleepAttempts++; if (VerifyWeAreConnected(wlanApi)) { testLogger.LogComment("We are still connected"); connectedAfterSleepSuccess++; } else { testLogger.LogComment("We are not still connected"); } Wlan.Sleep(1000); } } }
public void Scan() { Log("Scan Test Configuration Parameters: "); Log(m_AP1Config24GHz.GetTestParameter()); Log(m_AP1Config5GHz.GetTestParameter()); Log(m_AP2Config24GHz.GetTestParameter()); Log(m_AP2Config5GHz.GetTestParameter()); SetupRouters(); // Turn on all Radios Log("Turning on all radios"); AC.SetRadio24GHzState(routers[0], true); AC.SetRadio24GHzState(routers[1], true); AC.SetRadio5GHzState(routers[0], true); AC.SetRadio5GHzState(routers[1], true); LogMajor("Turning on Airplane Mode"); Api.SetRadioState(TestInterface, false); EventHandler <EventArrivedEventArgs> ETWCallback = null; ETWCallback = (object sender, EventArrivedEventArgs properties) => { LogEtwEvent(properties); }; var wlanEtwWatcher = new WlanEtwWatcher(); wlanEtwWatcher.EventArrived += ETWCallback; Log("Start ETW Tracing"); wlanEtwWatcher.Start(); bool Radio_0_24Ghz_Found = false; bool Radio_1_24Ghz_Found = false; bool Radio_0_5Ghz_Found = false; bool Radio_1_5Ghz_Found = false; string Reason_Radio_0_24Ghz_Found = null; string Reason_Radio_1_24Ghz_Found = null; string Reason_Radio_0_5Ghz_Found = null; string Reason_Radio_1_5Ghz_Found = null; try { Log("Sleeping for a second"); Wlan.Sleep(1 * 1000); // 1s LogMajor("Turning off Airplane Mode"); Api.SetRadioState(TestInterface, true); for (int i = 0; i < 4; i++) { Log("Scan Iteration " + i); if (i == 0) { // First scan is always with a flush so that we dont get old data LogMajor("Calling (public) scan with flush"); Api.Scan(TestInterface.Id, true, new TimeSpan(0, 0, 10)); } else if (ScanningConfiguration.IssueMulitpleScans == true) { // Additional scans are without flush LogMajor("Calling (internal) scan without flush"); Api.Scan(TestInterface.Id, false, new TimeSpan(0, 0, 10)); } // If any network is marked hidden, we need to specifically search for those for (int j = 0; j < 2; j++) { if (APConfigs[j].BeaconEnabled_24GHZ == false) { LogMajor("Calling (public) scan for " + APConfigs[j].SSID_24GHZ); Api.Scan(TestInterface.Id, false, APConfigs[j].SSID_24GHZ, new TimeSpan(0, 0, 10)); } if (APConfigs[j].BeaconEnabled_5GHZ == false) { LogMajor("Calling (public) scan for " + APConfigs[j].SSID_5GHZ); Api.Scan(TestInterface.Id, false, APConfigs[j].SSID_5GHZ, new TimeSpan(0, 0, 10)); } } if (!Radio_0_24Ghz_Found) { LogMajor("Scan : Locating " + APConfigs[0].SSID_24GHZ + " in bssid list"); if (Helpers.ValidateNetworkVisible(Api, APConfigs[0], false, out Reason_Radio_0_24Ghz_Found)) { LogMajor(APConfigs[0].SSID_24GHZ + "found in scan list "); Radio_0_24Ghz_Found = true; } else { LogMajor("ValidateNetworkVisible failed for " + APConfigs[0].SSID_24GHZ); } } if (!Radio_1_24Ghz_Found) { LogMajor("Scan : Locating " + APConfigs[1].SSID_24GHZ + " in bssid list"); if (Helpers.ValidateNetworkVisible(Api, APConfigs[1], false, out Reason_Radio_1_24Ghz_Found)) { LogMajor(APConfigs[1].SSID_24GHZ + "found in scan list "); Radio_1_24Ghz_Found = true; } else { LogMajor("ValidateNetworkVisible failed for " + APConfigs[1].SSID_24GHZ); } } if (!ScanningConfiguration.DeviceSupports5Ghz) { if (Radio_0_24Ghz_Found && Radio_1_24Ghz_Found) { LogMajor("Scan: Located all routers"); return; } else { LogMajor("Scan: Not yet located all routers "); LogMajor("Router 0 2.4Ghz Found =" + Radio_0_24Ghz_Found); LogMajor("Router 1 2.4Ghz Found =" + Radio_1_24Ghz_Found); continue; // skip 5Ghz } } if (!Radio_0_5Ghz_Found) { LogMajor("Scan : Locating " + APConfigs[0].SSID_5GHZ + " in bssid list"); if (Helpers.ValidateNetworkVisible(Api, APConfigs[0], true, out Reason_Radio_0_5Ghz_Found)) { LogMajor(APConfigs[0].SSID_5GHZ + " found in scan list"); Radio_0_5Ghz_Found = true; } else { LogMajor("ValidateNetworkVisible failed for " + APConfigs[0].SSID_5GHZ); } } if (!Radio_1_5Ghz_Found) { LogMajor("Scan : Locating " + APConfigs[1].SSID_5GHZ + " in bssid list"); if (Helpers.ValidateNetworkVisible(Api, APConfigs[1], true, out Reason_Radio_1_5Ghz_Found)) { LogMajor(APConfigs[1].SSID_5GHZ + " found in scan list"); Radio_1_5Ghz_Found = true; } else { LogMajor("ValidateNetworkVisible failed for " + APConfigs[1].SSID_5GHZ); } } if (Radio_0_24Ghz_Found && Radio_1_24Ghz_Found && Radio_0_5Ghz_Found && Radio_1_5Ghz_Found) { LogMajor("Scan: Located all routers"); return; } LogMajor("Scan: Not yet located all routers "); LogMajor("Router 0 2.4Ghz Found =" + Radio_0_24Ghz_Found); LogMajor("Router 1 2.4Ghz Found =" + Radio_1_24Ghz_Found); LogMajor("Router 0 5Ghz Found =" + Radio_0_5Ghz_Found); LogMajor("Router 1 5Ghz Found =" + Radio_1_5Ghz_Found); } } catch (Exception error) { LogMajor(error.ToString()); throw; } finally { wlanEtwWatcher.Dispose(); } LogMajor("Error locating all routers"); if (!Radio_0_24Ghz_Found) { LogMajor("Scanning - " + Reason_Radio_0_24Ghz_Found); throw new Exception(Reason_Radio_0_24Ghz_Found); } if (!Radio_1_24Ghz_Found) { LogMajor("Scanning - " + Reason_Radio_1_24Ghz_Found); throw new Exception(Reason_Radio_1_24Ghz_Found); } if (ScanningConfiguration.DeviceSupports5Ghz) { if (!Radio_0_5Ghz_Found) { LogMajor("Scanning - " + Reason_Radio_0_5Ghz_Found); throw new Exception(Reason_Radio_0_5Ghz_Found); } if (!Radio_1_5Ghz_Found) { LogMajor("Scanning - " + Reason_Radio_1_5Ghz_Found); throw new Exception(Reason_Radio_1_5Ghz_Found); } } }
private void AssociateDifferentAP(int firstRouterIndex, int secondRouterIndex, bool b5GhzFirstRouter, bool b5GhzSecondRouter, bool bHibernate) { Log("Deleting all wlan profiles"); DeleteProfiles(); Log("Starting Echo Services"); CreateEchoServer(); //Radios of all APs are turned on by the SetupRoutersIfNeeded(); Log("Setting up Routers"); SetupRoutersIfNeeded(); string Profile; APConfig ap1Config = m_APConfigs[firstRouterIndex]; APConfig ap2Config = m_APConfigs[secondRouterIndex]; string ap1_ssid = (b5GhzFirstRouter) ? ap1Config.SSID_5GHZ : ap1Config.SSID_24GHZ; string ap2_ssid = (b5GhzSecondRouter) ? ap2Config.SSID_5GHZ : ap2Config.SSID_24GHZ; string ap2_bssid = (b5GhzSecondRouter) ? ap2Config.BSSID_5GHZ : ap2Config.BSSID_24GHZ; //Turn off all APs SetRadioState(0, false, false); SetRadioState(0, false, true); SetRadioState(1, false, false); SetRadioState(1, false, true); //Turn on AP used for this run SetRadioState(firstRouterIndex, true, b5GhzFirstRouter); LogMajor("Associate with manual profile to " + ap1_ssid + " - Enter lower powerstate turn off first AP and turn on second AP - Wake - Connect with manual profile to " + ap2_ssid); Log("Creating a manual profile for SSID " + ap1_ssid); Profile = CreateProfile(firstRouterIndex, ConnectionMode.Manual, b5GhzFirstRouter); LogMajor("Connecting to " + ap1_ssid); if (!ConnectToAP(ap1_ssid)) { return; } LogMajor("Validating association bssid"); if (!ValidateRadioAssociation(firstRouterIndex, b5GhzFirstRouter)) { return; } LogMajor("Validating connection by connecting to echo services and performing echo"); if (!PerformEcho(firstRouterIndex, b5GhzFirstRouter)) { return; } int delayInSeconds = 30; int ScenarioToRun = 1; //switch LogMajor("Putting machine into lower power state for 2 minutes. " + ap1_ssid + " will turn off and " + ap2_ssid + "will turn on"); m_ApConfigClient.StartApScenarioAssoc(m_Routers[secondRouterIndex], m_Routers[firstRouterIndex], ScenarioToRun, delayInSeconds, b5GhzSecondRouter, b5GhzFirstRouter); m_ApConfigClient.Disconnect(); //must disconnect from ap controller before going to sleep if (bHibernate) { LogMajor("Entering hibernate"); m_PowerManager.Sleep(120 * 1000, SleepState.S4); } else { LogMajor("Entering deepest supported sleep"); m_PowerManager.DeepestSleep(120 * 1000); } LogMajor("Sleeping for 30 seconds after wake up"); Wlan.Sleep(30 * 1000); // 30s m_ApConfigClient.Connect(); //must reconnect to ap controller after waking up //scan for new AP Helpers.IssueScanWaitForSSIDToAppearInScanList(m_WlanApi, m_TestInterface, ap2_ssid, ap2_bssid, 60, 500); //connect to next AP. Log("Creating a manual profile for SSID " + ap2_ssid); Profile = CreateProfile(secondRouterIndex, ConnectionMode.Manual, b5GhzSecondRouter); LogMajor("Connecting to " + ap2_ssid); if (!ConnectToAP(ap2_ssid)) { return; } LogMajor("Validating association bssid"); if (!ValidateRadioAssociation(secondRouterIndex, b5GhzSecondRouter)) { return; } LogMajor("Validating connection by connecting to echo services and performing echo"); if (!PerformEcho(secondRouterIndex, b5GhzSecondRouter)) { return; } m_WlanApi.DeleteAllProfiles(m_TestInterface.Id); }
private void AssociateSameAP(int routerIndex, bool b5Ghz, bool bHibernate) { Log("Deleting all wlan profiles"); DeleteProfiles(); Log("Starting Echo Services"); CreateEchoServer(); //Radios of all APs are turned on by the SetupRoutersIfNeeded(); Log("Setting up Routers"); SetupRoutersIfNeeded(); string Profile; APConfig apConfig = m_APConfigs[routerIndex]; string ap_ssid = (b5Ghz) ? apConfig.SSID_5GHZ : apConfig.SSID_24GHZ; //Turn off all APs SetRadioState(0, false, false); SetRadioState(0, false, true); SetRadioState(1, false, false); SetRadioState(1, false, true); //Turn on AP used for this run SetRadioState(routerIndex, true, b5Ghz); LogMajor("Associate with manual profile to " + ap_ssid + " - Enter lower powerstate - Wake - Verify connectivity to same AP"); Log("Creating a manual profile for SSID " + ap_ssid); Profile = CreateProfile(routerIndex, ConnectionMode.Manual, b5Ghz); LogMajor("Connecting to " + ap_ssid); if (!ConnectToAP(ap_ssid)) { return; } LogMajor("Validating association bssid"); if (!ValidateRadioAssociation(routerIndex, b5Ghz)) { return; } LogMajor("Validating connection by connecting to echo services and performing echo"); if (!PerformEcho(routerIndex, b5Ghz)) { return; } m_ApConfigClient.Disconnect(); //must disconnect from ap controller before going to sleep if (bHibernate) { LogMajor("Entering hibernate"); m_PowerManager.Sleep(120 * 1000, SleepState.S4); } else { LogMajor("Entering deepest supported sleep"); m_PowerManager.DeepestSleep(120 * 1000); } LogMajor("Sleeping for 30 seconds after wake up"); Wlan.Sleep(30 * 1000); // 30s m_ApConfigClient.Connect(); //must reconnect to ap controller after waking up if (!Helpers.IsConnected(m_WlanApi, m_TestInterface)) { LogError("After resuming system not connected to " + ap_ssid); return; } LogMajor("Validating association bssid"); if (!ValidateRadioAssociation(routerIndex, b5Ghz)) { return; } LogMajor("Validating connection by connecting to echo services and performing echo"); if (!PerformEcho(routerIndex, b5Ghz)) { return; } m_WlanApi.DeleteAllProfiles(m_TestInterface.Id); }
private void ConnectForIntegrityCheck(ApConfigClient apConfigClient, int port, int streamBytes) { 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) { return; } if (apConfigCreated == false) { var currentConfig1 = WlanAccessPointHelper.CreateWirelessAccessPoint(AuthenticationMethod.WPA2Personal, EncryptionMethod.AES, PhyType.n, "Password", AuthenticationMethod.WPA2Personal, EncryptionMethod.AES, PhyType.n, "Password"); var currentConfig2 = WlanAccessPointHelper.CreateWirelessAccessPoint(AuthenticationMethod.WPA2Personal, EncryptionMethod.AES, PhyType.n, "Password", AuthenticationMethod.WPA2Personal, EncryptionMethod.AES, PhyType.n, "Password"); ConfiguredSSIDs configuredSSID1 = new ConfiguredSSIDs("", ""); ConfiguredSSIDs configuredSSID2 = new ConfiguredSSIDs("", ""); if (apConfigClient.ApplyConfiguration(routers[0], currentConfig1, out configuredSSID1)) { currentConfig1.SSID_24GHZ = configuredSSID1.TwoPoint4GhzSSID; currentConfig1.SSID_5GHZ = configuredSSID1.FiveghzSSID; testLogger.LogComment("Successfully applied the Configuration to AP[0]"); } else { testLogger.LogError("Unable to apply the configuration to AP [0]"); } testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Applying AP Configuration to AP[1] {0}", currentConfig2.SSID_24GHZ)); if (apConfigClient.ApplyConfiguration(routers[1], currentConfig2, out configuredSSID2)) { currentConfig2.SSID_24GHZ = configuredSSID1.TwoPoint4GhzSSID; currentConfig2.SSID_5GHZ = configuredSSID1.FiveghzSSID; testLogger.LogComment("Successfully applied the Configuration to AP[2]"); } else { testLogger.LogError("Unable to apply the configuration to AP[2]"); } string profile1; string profile2; profile1 = currentConfig1.CreateProfile24ghz(ConnectionMode.Manual, false); profileName1 = currentConfig1.SSID_24GHZ; profile2 = currentConfig2.CreateProfile24ghz(ConnectionMode.Manual, false); profileName2 = currentConfig2.SSID_24GHZ; testLogger.LogComment(profile1); wlanApi.CreateProfile(wlanInterface.Id, profile1); wlanApi.CreateProfile(wlanInterface.Id, profile2); testLogger.LogComment("Wait to allow APs to beacon"); Wlan.Sleep(10000); apConfigCreated = true; } int retries = 3; while (retries > 0) { retries--; testLogger.LogComment("Scan"); wlanApi.TryScan(wlanInterface.Id, false, ScanWait); try { testLogger.LogComment(String.Format(CultureInfo.InvariantCulture, "Attempt to Connect to SSID : {0}", profileName1)); wlanApi.ProfileConnect(wlanInterface.Id, profileName1, ConnectWait); break; } catch (Exception) { testLogger.LogComment("Connect failed."); if (retries == 0) { testLogger.LogError(String.Format(CultureInfo.InvariantCulture, "Could not connect to SSID: {0}", profileName1)); return; } } } testLogger.LogComment("Wait for DHCP"); Microsoft.Test.Networking.Kit.Helpers.WaitForWlanConnectivity(wlanInterface.Id, 1000 * 15, testLogger); } }
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); } } } } }
public void Stress() { // Populate Stress Modules StressModules = new List <StressModule>(); StressModules.Add(new ConnectDisconnectStress(random, routers, testLogger)); StressModules.Add(new AirplaneModeStress(random, routers, testLogger)); StressModules.Add(new ScanStress(random, routers, testLogger)); //StressModules.Add(new SleepStress(random, routers, testLogger)); apConfigCreated = false; testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Starting Stress at : {0}", DateTime.Now)); DateTime endTime = DateTime.Now.Add(new TimeSpan(0, TestDuration, 0)); testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Stress will end around : {0}", endTime)); bool testFailed = false; if (TestDuration < 50) { failForNotEnoughTime = true; testLogger.LogError("The test will fail because it is not scheduled to run long enough. Stress will still run but will ultimatly fail. To fix this inrease the stress run time."); } else { failForNotEnoughTime = false; } if (RunIntegrityCheck() == false) { testLogger.LogError("Ending test because of failed integrity check."); return; } while (DateTime.Now < endTime) { if (nextIntegrityCheckTime < DateTime.Now) { if (RunIntegrityCheck() == false) { testLogger.LogError("Ending test because of failed integrity check."); break; } else { continue; } } StressModule stressModule = null; try { stressModule = GetNextStressModule(); testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Starting test {0}", stressModule.Name)); stressModule.Run(profileName1, profileName2); // Wait a few seconds between stress run and next item Wlan.Sleep(5000); } catch (Exception error) { if (stressModule == null) { testLogger.LogError(string.Format(CultureInfo.InvariantCulture, "Exception when preparing test: {0}", error.ToString())); } else { testLogger.LogError(string.Format(CultureInfo.InvariantCulture, "Exception when running test: {0} {1}", stressModule.Name, error.ToString())); } testFailed = true; break; } } bool integrityCheck = true; if (RunIntegrityCheck() == false) { testLogger.LogError("Ending test because of failed integrity check."); integrityCheck = false; } 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]; testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Deleting Profile {0}", profileName1)); wlanApi.TryDeleteProfile(wlanInterface.Id, profileName1); testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Deleting Profile {0}", profileName2)); wlanApi.TryDeleteProfile(wlanInterface.Id, profileName2); } foreach (var stressModule in StressModules) { stressModule.PrintResults(); } Verify.IsTrue(testFailed == false); Verify.IsTrue(integrityCheck == true); if (failForNotEnoughTime == true) { testLogger.LogError("The stress test failed because it was not scheduled to run at a long enough duration. To fix this inrease the stress run time."); } Verify.IsTrue(failForNotEnoughTime == false); }
public void TestDot11wConnection() { Guid interfaceId; testLogger.LogComment("Testing 802.11w Connection to AP with SSID " + dot11wSSID + " and password " + dot11wPassword); 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]; interfaceId = wlanInterface.Id; // Delete Profile if present DisconnectAndDeleteProfile(wlanApi); // Scan testLogger.LogComment("Scan"); wlanApi.Scan(wlanInterface.Id, false, ScanWait); // Check to see if SSID is in scan list testLogger.LogComment("Check to see if SSID is in scan list"); var networkList = wlanApi.GetAvailableNetworkList(interfaceId); bool found = false; foreach (WlanNetwork network in networkList) { if (String.Compare(network.Ssid, dot11wSSID, StringComparison.Ordinal) == 0) { found = true; break; } } if (found == false) { testLogger.LogError("Could not find 11w router in scan list: " + dot11wSSID); testLogger.LogResult(TestResult.Failed); return; } else { testLogger.LogComment("Found the 11w router in the scan list: " + dot11wSSID); } // Create Profile string profile = GenerateProfile(); testLogger.LogComment("Creating Profile"); wlanApi.CreateProfile(interfaceId, profile); // Connect testLogger.LogComment("Connecting to AP"); wlanApi.ProfileConnect(interfaceId, dot11wSSID, new TimeSpan(0, 0, 30)); } // Check MFP Status bool mfpStatus = IsMfpNeogotiated(interfaceId); testLogger.LogComment("IsMfpNeogotiated == " + mfpStatus); if (mfpStatus == false) { testLogger.LogError("The device connected to the dot11w router but IsMfpNeogotiated == false"); testLogger.LogResult(TestResult.Failed); return; } if (enableSleepTest) { PowerManager powerManager; powerManager = new PowerManager(); // Wait for DHCP Stable testLogger.LogComment("Wait for DHCP to be stable"); Wlan.Sleep(1000 * 60 * 2); testLogger.LogComment("Going into Connected standby/Sleep for 1 minute"); powerManager.DeepestSleep(60); using (Wlan wlanApi = new Wlan()) { bool isConnected = IsConnected(wlanApi); if (isConnected == false) { testLogger.LogError("After waking from connected standby the device is no longer connected to the AP"); } else { testLogger.LogComment("After waking from connected standby the device is still connected to the AP"); } } // Check MFP Status mfpStatus = IsMfpNeogotiated(interfaceId); testLogger.LogComment("IsMfpNeogotiated == " + mfpStatus); if (mfpStatus == false) { testLogger.LogError("The device connected to the dot11w router but IsMfpNeogotiated == false"); return; } } }
public void GradualLossOfSignal(bool b5Ghz) { LogMajor("Scenario - Gradual loss of signal starts"); LogMajor("Resetting Wlan Adaptor"); ToggleAdapter(); SetupRoutersAndProfilesIfNeeded(); string profilename = null; if (b5Ghz) { profilename = APConfigs[0].SSID_5GHZ; } else { profilename = APConfigs[0].SSID_24GHZ; } LogMajor("Testing Roaming with router " + profilename); LogMajor("Turning Router 0 on"); if (!SetRadioState(0, true, b5Ghz)) { return; } LogMajor("Turning Router 1 on"); if (!SetRadioState(1, true, b5Ghz)) { return; } LogMajor("Calling WlanConnect using a Wlan Profile " + profilename); if (!ConnectToAP(profilename)) { return; } LogMajor("Making a TCP connection to Echo Services"); if (!ConnectToEchoServer()) { return; } LogMajor("Turning Router 0 on"); if (!SetRadioState(0, true, b5Ghz)) { return; } LogMajor("Turning Router 1 on"); if (!SetRadioState(1, true, b5Ghz)) { return; } for (int power0 = 84, power1 = 4; power0 >= 4 && power1 <= 84;) { if (power0 < 4) { power0 = 4; } if (power1 > 84) { power1 = 84; } if (power0 == 4) { LogMajor("Turning Router 0 off"); if (!SetRadioState(0, false, b5Ghz)) { return; } } LogMajor("Setting txPower on Router 0 to " + power0); SetRadioPower(0, power0, b5Ghz); LogMajor("Setting txPower on Router 1 to " + power1); SetRadioPower(1, power1, b5Ghz); Wlan.Sleep(500); LogMajor("Currently Associated with " + Helpers.GetBSSID(Api, TestInterface)); LogMajor("Ensuring echo Network session is alive and functional by performing echo"); PerformEcho(); power0 -= 10; power1 += 10; Wlan.Sleep(500); } LogMajor("Scenario - Sudden loss of signal ends"); }
public override void Run(string profileName1, string profileName2) { DateTime endTime = DateTime.Now.Add(new TimeSpan(0, 5, 0)); TimeSpan waiterTimeout = new TimeSpan(0, 0, 10); 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]; var radioStateList = wlanApi.GetRadioState(wlanInterface); if (radioStateList[0].SoftwareRadioState == RadioState.Off) { testLogger.LogComment("Turning Radio On"); WlanNotificationWaiter waiterOnSetup = wlanApi.CreateEventWaiter(WLAN_NOTIFICATION_MSM.wlan_notification_msm_radio_state_change); wlanApi.SetRadioState(wlanInterface, 0, true); waiterOnSetup.Wait(waiterTimeout); } try { while (DateTime.Now < endTime) { if (Random.Next(0, 2) == 1) { // Slow toggle testLogger.LogComment("Slow Toggle"); int iterations = Random.Next(10); for (int toggleLooper = 0; toggleLooper < iterations; toggleLooper++) { testLogger.LogComment("Turning Radio Off"); SlowToggles++; WlanNotificationWaiter waiterOff = wlanApi.CreateEventWaiter(WLAN_NOTIFICATION_MSM.wlan_notification_msm_radio_state_change); wlanApi.SetRadioState(wlanInterface, 0, false); waiterOff.Wait(waiterTimeout); testLogger.LogComment("Turning Radio On"); WlanNotificationWaiter waiterOn = wlanApi.CreateEventWaiter(WLAN_NOTIFICATION_MSM.wlan_notification_msm_radio_state_change); wlanApi.SetRadioState(wlanInterface, 0, true); waiterOn.Wait(waiterTimeout); } } else { // Fast Toggle testLogger.LogComment("Fast Toggle"); int iterations = Random.Next(10); for (int toggleLooper = 0; toggleLooper < iterations; toggleLooper++) { testLogger.LogComment("Turning Radio Off"); FastToggles++; wlanApi.SetRadioState(wlanInterface, 0, false); Wlan.Sleep(Random.Next(100, 750)); testLogger.LogComment("Turning Radio On"); wlanApi.SetRadioState(wlanInterface, 0, true); Wlan.Sleep(Random.Next(100, 750)); } testLogger.LogComment("Sleeping for a few seconds to allow the driver to calm down"); Wlan.Sleep(10000); } ScanAttempts++; testLogger.LogComment("Scanning"); wlanApi.TryScan(wlanInterface.Id, true, WlanStress.ScanWait); var list = wlanApi.GetAvailableNetworkList(wlanInterface.Id); if (list.Count > 0) { ScanSuccess++; } else { testLogger.LogComment("Scanning failed"); } } } finally { radioStateList = wlanApi.GetRadioState(wlanInterface); if (radioStateList[0].SoftwareRadioState == RadioState.Off) { testLogger.LogComment("Turning Radio On"); WlanNotificationWaiter waiterOnCleanup = wlanApi.CreateEventWaiter(WLAN_NOTIFICATION_MSM.wlan_notification_msm_radio_state_change); wlanApi.SetRadioState(wlanInterface, 0, true); waiterOnCleanup.Wait(waiterTimeout); } } } }
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); } } }