/// <summary> /// Sends probe message to specified address from specified address, and starts listening for answer /// </summary> /// <param name="local">Local address to send message from</param> /// <param name="remote">Address to send message to, if IPAddress.None multicast message will be sent</param> protected void ProbeInternal(IPAddress local, IPAddress remote) { List <DiscoveryErrorEventArgs> errors = new List <DiscoveryErrorEventArgs>(); List <DeviceDiscoveryData> devices = new List <DeviceDiscoveryData>(); DiscoveryUtils.DiscoveryType[][] types = new DiscoveryUtils.DiscoveryType[][] { DiscoveryUtils.GetOnvif10Type(), DiscoveryUtils.GetOnvif20Type() }; Discovery discovery = new Discovery(local); //passing null instead of types will accept devices according to Test Spec //if types is not null - devices which contains at least one type from types discovery.Discovered += (s, e) => OnDeviceDiscovered(s, e, devices, errors, types); discovery.DiscoveryFinished += (s, e) => OnDiscoveryFinished(s, e, devices, errors); discovery.ReceiveError += (s, e) => OnDiscoveryError(s, e, errors); _queriesRunning = 1; if (remote != IPAddress.None) { discovery.Probe(remote, types); } else { //probe multicast address discovery.Probe(types); } if (DiscoveryStarted != null) { DiscoveryStarted(); } }
/// <summary> /// Handles check device by IP button click event /// </summary> /// <param name="sender">Event sender</param> /// <param name="e">Event argument</param> private void btnCheckIP_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(tbDeviceIP.Text)) { try { IPAddress deviceIP = DiscoveryUtils.GetIP(tbDeviceIP.Text, false); if (deviceIP != null) { ClearServiceInfo(); _autoSelectDevice = true; //set flag for auto select device if found _probeAnswered = false; _unicastProbing = true; #if true NICListItem item = (NICListItem)cmbNICs.SelectedItem; Controller.ProbeDevice(item.NIC.IP, deviceIP); #else Controller.ProbeDevice(deviceIP); #endif } else { ShowError("Invalid IP address or hostname"); } } catch (Exception ex) { ShowError(ex); } } }
public void SoapFaultMessageTest() { RunTest(() => { RunStep(() => { try { SoapMessage <WSD.ProbeMatchesType> response = ProbeDevice( false, //new DiscoveryUtils.DiscoveryType[][] { DiscoveryUtils.GetOnvif10Type(), DiscoveryUtils.GetOnvif20Type() }, null, DiscoveryUtils.GetManadatoryScopes(), "InvalidMatchRule"); throw new AssertException(response != null ? "DUT responded to invalid probe message" : "DUT did not respond"); } catch (SoapFaultException ex) { string reason; if (!DiscoveryUtils.IsCorrectSoapFault( ex.Fault, "Sender", SoapBuilder.SoapEnvelopeUri, "MatchingRuleNotSupported", DiscoveryUtils.WS_DISCOVER_NS, out reason)) { throw new AssertException(reason); } } }, Resources.StepInvalidProbe_Title); }); }
/// <summary> /// Handles check device by IP button click event /// </summary> /// <param name="sender">Event sender</param> /// <param name="e">Event argument</param> private void btnCheckIP_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(tbDeviceIP.Text)) { try { IPAddress deviceIP = DiscoveryUtils.GetIP(tbDeviceIP.Text, false); if (deviceIP != null) { ClearServiceInfo(); _autoSelectDevice = true; //set flag for auto select device if found _probeAnswered = false; _unicastProbing = true; Controller.ProbeDevice(deviceIP); } else { MessageBox.Show(this, "Invalid IP address or hostname", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(this, "Unexpected error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Validates incoming Hello message /// </summary> /// <param name="message">Hello message</param> /// <param name="reason">reason why message is invalid, null if message is valid</param> /// <returns>true, if message is valid</returns> protected bool ValidateHelloMessage(SoapMessage <WSD.HelloType> message, string[] scopes, out string reason) { bool res = true; reason = null; try { //check Types namespace WSD.HelloType hello = message.Object; if (hello.Types == null) { reason = Resources.ErrorNoTypes_Text; return(false); } if (!DiscoveryUtils.CheckDeviceHelloType(message, out reason)) { return(false); } if (hello.EndpointReference == null) { reason = Resources.ErrorNoEndpointReference_Text; return(false); } if (hello.Scopes == null) { reason = Resources.ErrorNoScopes_Text; return(false); } if (hello.Scopes.Text == null) { reason = Resources.ErrorNoScopesText_Text; return(false); } //check mandatory scopes string missingScope = DiscoveryUtils.GetMissingMandatoryScope(hello.Scopes.Text); if (!string.IsNullOrEmpty(missingScope)) { reason = string.Format(Resources.ErrorMissingMandatoryScope_Format, missingScope); return(false); } //check optional scopes if (scopes != null) { missingScope = DiscoveryUtils.GetMissingScope(hello.Scopes.Text, scopes); if (!string.IsNullOrEmpty(missingScope)) { reason = string.Format(Resources.ErrorMissingScope_Format, missingScope); return(false); } } } catch (Exception e) { reason = e.Message; res = false; } return(res); }
DiscoveredExample MapToDiscovered(ExampleBase example, string binaryPath) { var sourceInfo = debugInfoProvider.GetSourceInfo(example); var discoveredExample = DiscoveryUtils.MapToDiscovered(example, binaryPath, sourceInfo); return(discoveredExample); }
void discovery_Discovered(object sender, DiscoveryMessageEventArgs e) { lock (this) { if (_probeMessage != null) { return; } System.Diagnostics.Debug.WriteLine("Discovered"); _probeMessage = DiscoveryUtils.XmlToString(e.Message.Raw); _discoveredEvent.Set(); } }
/// <summary> /// Sends probe message to specified address from specified address, and starts listening for answer /// </summary> /// <param name="local">Local address to send message from</param> /// <param name="remote">Address to send message to, if IPAddress.None multicast message will be sent</param> protected void ProbeInternal(IPAddress local, IPAddress remote) { List <DiscoveryErrorEventArgs> errors = new List <DiscoveryErrorEventArgs>(); List <DeviceDiscoveryData> devices = new List <DeviceDiscoveryData>(); DiscoveryUtils.DiscoveryType[][] types = new DiscoveryUtils.DiscoveryType[][] { DiscoveryUtils.GetOnvif10Type(), DiscoveryUtils.GetOnvif20Type() }; Discovery discovery = new Discovery(local); //passing null instead of types will accept devices according to Test Spec //if types is not null - devices which contains at least one type from types discovery.Discovered += (s, e) => OnDeviceDiscovered(s, e, devices, errors, types); discovery.DiscoveryFinished += (s, e) => OnDiscoveryFinished(s, e, devices, errors); discovery.ReceiveError += (s, e) => OnDiscoveryError(s, e, errors); string[] scopes = null; string searchScopes = View.SearchScopes; if (!string.IsNullOrEmpty(searchScopes)) { searchScopes = searchScopes.Replace(Environment.NewLine, " "); scopes = searchScopes.Split(' '); List <string> correctedScopes = new List <string>(); foreach (string scope in scopes) { if (!string.IsNullOrEmpty(scope)) { correctedScopes.Add(scope); } } scopes = correctedScopes.ToArray(); } _queriesRunning = 1; if (remote != IPAddress.None) { discovery.Probe(remote, types, scopes); } else { //probe multicast address discovery.Probe(types, scopes); } if (DiscoveryStarted != null) { DiscoveryStarted(); } }
public void SearchDeviceScopeTypesTest() { RunTest(() => { TestTool.Proxies.Onvif.Scope[] scopes = GetScopes(); string missingScope = DiscoveryUtils.GetMissingMandatoryScope(scopes); Assert(string.IsNullOrEmpty(missingScope), string.Format(Resources.ErrorMissingMandatoryScope_Format, missingScope), "Validating device scopes"); SoapMessage <WSD.ProbeMatchesType> probeMatch = ProbeDeviceStep(true, DiscoveryUtils.GetManadatoryScopes()); string reason = null; Assert(ValidateProbeMatchMessage(probeMatch, out reason), reason, Resources.StepValidateProbeMatch_Title); }); }
/// <summary> /// Handles device discovered event /// </summary> /// <param name="sender">Event sender</param> /// <param name="e">Event parameter</param> /// <param name="allDevices"></param> /// <param name="errors"></param> /// <param name="types"></param> protected void OnDeviceDiscovered(object sender, DiscoveryMessageEventArgs e, List <DeviceDiscoveryData> allDevices, List <DiscoveryErrorEventArgs> errors, DiscoveryUtils.DiscoveryType[][] types) { if (DeviceDiscovered != null) { List <DeviceDiscoveryData> devices = DiscoveryUtils.GetDevices(e.Message.ToSoapMessage <WSD.ProbeMatchesType>(), e.Sender, types); allDevices.AddRange(devices); foreach (DeviceDiscoveryData device in devices) { DeviceDiscovered(device); } } }
/// <summary> /// Handles device discovered event /// </summary> /// <param name="sender">Event sender</param> /// <param name="e">Event parameter</param> protected void OnDeviceDiscovered(object sender, DiscoveryMessageEventArgs e) { if (DeviceDiscovered != null) { List <DeviceDiscoveryData> devices = DiscoveryUtils.GetDevices(e.Message.ToSoapMessage <WSD.ProbeMatchesType>(), e.Sender); if (devices.Count == 0) { OnDiscoveryError(this, new DiscoveryErrorEventArgs(new Exception("Device type is not " + DiscoveryUtils.ONVIF_DISCOVER_TYPES), null)); } else { foreach (DeviceDiscoveryData device in devices) { DeviceDiscovered(device); } } } }
public void UnicastProbeMessageTest() { RunTest(() => { //5.3 Scope[] scopes = GetScopes(); string missingScope = DiscoveryUtils.GetMissingMandatoryScope(scopes); Assert(string.IsNullOrEmpty(missingScope), string.Format(Resources.ErrorMissingMandatoryScope_Format, missingScope), "Validating device scopes"); SoapMessage <WSD.ProbeMatchesType> probeMatch = ProbeDeviceStep(false, DiscoveryUtils.GetManadatoryScopes()); string reason = null; Assert(ValidateProbeMatchMessage(probeMatch, out reason), reason, Resources.StepValidateProbeMatch_Title); //5.4 probeMatch = ProbeDeviceStep(false, null); Assert(ValidateProbeMatchMessage(probeMatch, out reason), reason, Resources.StepValidateProbeMatch_Title); //5.5 InvalidProbeDeviceStep(false, new string[] { "InvalidScope1", "InvalidScope1" }); }); }
/// <summary> /// Validates ProbeMatches messages /// </summary> /// <param name="message">Message to be validated</param> /// <param name="reason">Reason why message is invalid</param> /// <returns>true, if message is valid</returns> protected bool ValidateProbeMatchMessage(SoapMessage <WSD.ProbeMatchesType> message, out string reason) { bool mode1 = Features.Contains(Feature.DiscoveryTypesDnNetworkVideoTransmitter); bool mode2 = Features.Contains(Feature.DiscoveryTypesTdsDevice); bool res = true; reason = null; try { //check Types namespace if (message.Object.ProbeMatch == null) { reason = Resources.ErrorNoProbeMatch_Text; return(false); } bool found = false; for (int i = 0; i < message.Object.ProbeMatch.Length; i++) { WSD.ProbeMatchType match = message.Object.ProbeMatch[i]; if (DiscoveryUtils.CheckDeviceMatchType(message, i, out reason, mode1, mode2)) { if (!ValidateProbeMatch(match, out reason)) { return(false); } found = true; break; } } if (!found) { return(false); } } catch (Exception e) { reason = e.Message; res = false; } return(res); }
/// <summary> /// Validates ProbeMatches messages /// </summary> /// <param name="message">Message to be validated</param> /// <param name="reason">Reason why message is invalid</param> /// <returns>true, if message is valid</returns> protected bool ValidateProbeMatchMessage(SoapMessage <WSD.ProbeMatchesType> message, out string reason) { bool res = true; reason = null; try { //check Types namespace if (message.Object.ProbeMatch == null) { reason = Resources.ErrorNoProbeMatch_Text; return(false); } bool found = false; for (int i = 0; i < message.Object.ProbeMatch.Length; i++) { WSD.ProbeMatchType match = message.Object.ProbeMatch[i]; if (DiscoveryUtils.CheckDeviceMatchType(message, i)) { if (!ValidateProbeMatch(match, out reason)) { return(false); } found = true; break; } } if (!found) { reason = string.Format(Resources.ErrorIncorrectTypes_Format, DiscoveryUtils.ONVIF_DISCOVER_TYPES, DiscoveryUtils.ONVIF_NETWORK_WSDL_URL); return(false); } } catch (Exception e) { reason = e.Message; res = false; } return(res); }
protected void SearchDeviceScopeTypesTestWithTransofrmation(XmlTransformation transformation) { RunTest( () => { Scope[] scopes = GetScopes(); string missingScope = DiscoveryUtils.GetMissingMandatoryScope(scopes); Assert(string.IsNullOrEmpty(missingScope), string.Format(Resources.ErrorMissingMandatoryScope_Format, missingScope), "Validating device scopes"); XmlNamespacesTransformer transformer = new XmlNamespacesTransformer(transformation, false); SoapMessage <WSD.ProbeMatchesType> probeMatch = ProbeDeviceStep( true, //new DiscoveryUtils.DiscoveryType[][] { DiscoveryUtils.GetOnvif10Type() }, null, DiscoveryUtils.GetManadatoryScopes(), null, transformer.ProcessMessage); string reason = null; Assert(ValidateProbeMatchMessage(probeMatch, out reason), reason, Resources.StepValidateProbeMatch_Title); }); }
public TestSuiteParameters GetTestSuiteParameters() { TestSuiteParameters parameters = new TestSuiteParameters(); if (Device != null) { parameters.Address = Device.DeviceServiceAddress; //parameters.CameraUUID } if (string.IsNullOrEmpty(parameters.Address)) { Console.WriteLine("Mandatory parameters (Device address) not defined!"); return(null); } Timeouts defTimeouts = new Timeouts(); TestSettings defSettings = new TestSettings(); if (TestParameters != null) { parameters.MessageTimeout = (0 != TestParameters.MessageTimeout) ? TestParameters.MessageTimeout : defTimeouts.Message; parameters.RebootTimeout = (0 != TestParameters.RebootTimeout) ? TestParameters.RebootTimeout : defTimeouts.Reboot; parameters.RecoveryDelay = TestParameters.TimeBetweenRequests; parameters.TimeBetweenTests = TestParameters.TimeBetweenTests; parameters.OperationDelay = (0 != TestParameters.OperationDelay) ? TestParameters.OperationDelay : defSettings.OperationDelay; parameters.UserName = TestParameters.UserName; parameters.Password = TestParameters.Password; parameters.EnvironmentSettings = new EnvironmentSettings(); parameters.EnvironmentSettings.DefaultGateway = TestParameters.DefaultGatewayIpv4; parameters.EnvironmentSettings.DefaultGatewayIpv6 = TestParameters.DefaultGatewayIpv6; parameters.EnvironmentSettings.DnsIpv4 = TestParameters.DnsIpv4; parameters.EnvironmentSettings.DnsIpv6 = TestParameters.DnsIpv6; parameters.EnvironmentSettings.NtpIpv4 = TestParameters.NtpIpv4; parameters.EnvironmentSettings.NtpIpv6 = TestParameters.NtpIpv6; if (!string.IsNullOrEmpty(TestParameters.Address)) { // get all "own" addresses; List <NetworkInterfaceDescription> nics = DiscoveryHelper.GetNetworkInterfaces(); // select required address (compare strings) foreach (NetworkInterfaceDescription nic in nics) { if (nic.IP.ToString() == TestParameters.Address) { parameters.NetworkInterfaceController = nic; break; } } if (parameters.NetworkInterfaceController != null) { // define device IP bool ipv6 = (parameters.NetworkInterfaceController.IP != null) && (parameters.NetworkInterfaceController.IP.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6); parameters.CameraIP = DiscoveryUtils.GetIP(Device.DeviceIP, ipv6); } } parameters.UseEmbeddedPassword = TestParameters.UseEmbeddedPassword; parameters.Password1 = TestParameters.Password1; parameters.Password2 = TestParameters.Password2; parameters.SecureMethod = !string.IsNullOrEmpty(TestParameters.SecureMethod) ? TestParameters.SecureMethod : defSettings.SecureMethod; parameters.PTZNodeToken = TestParameters.PTZNodeToken; parameters.VideoSourceToken = TestParameters.VideoSourceToken; parameters.EventTopic = TestParameters.EventTopic; parameters.SubscriptionTimeout = (0 != TestParameters.SubscriptionTimeout) ? TestParameters.SubscriptionTimeout : defSettings.SubscriptionTimeout; parameters.TopicNamespaces = TestParameters.TopicNamespaces; parameters.RelayOutputDelayTimeMonostable = (0 != TestParameters.RelayOutputDelayTime) ? TestParameters.RelayOutputDelayTime : defSettings.RelayOutputDelayTimeMonostable; } // return(parameters); }
public void DeviceScopesConfigurationTest() { bool scopesAdded = false; string[] newScopes = null; bool scopesReplaced = false; List <string> oldNonfixedScopes = new List <string>(); RunTest <string[]>( new Backup <string[]>(() => { return(null); }), () => { //get and validate fixed scopes Scope[] scopes = GetScopes(); string missingScope = DiscoveryUtils.GetMissingMandatoryScope(scopes); Assert(string.IsNullOrEmpty(missingScope), string.Format(Resources.ErrorMissingMandatoryScope_Format, missingScope), "Validating device scopes"); //set fixed scopes fault validation SetFixedScopes(scopes); //set configurable scopes List <string> newNonfixedScopes = new List <string>(); newNonfixedScopes.Add("onvif://www.onvif.org/" + Guid.NewGuid().ToString()); foreach (Scope scope in scopes) { if (scope.ScopeDef == ScopeDefinition.Configurable) { oldNonfixedScopes.Add(scope.ScopeItem); foreach (string mandatoryScope in DiscoveryUtils.GetManadatoryScopes()) { if (scope.ScopeItem.Contains(mandatoryScope)) { if (!newNonfixedScopes.Contains(mandatoryScope)) { newNonfixedScopes.Add(mandatoryScope); } } } } } SetScopes(newNonfixedScopes.ToArray()); // fix for 10767 Sleep(2000); scopesReplaced = true; //add new scopes //begin wait before sending AddScopes, because Hello can be sent by NVT before response to AddScopes newScopes = new string[] { "onvif://www.onvif.org/" + Guid.NewGuid().ToString(), "onvif://www.onvif.org/" + Guid.NewGuid().ToString() }; bool canAddScopes = true; SoapMessage <WSD.HelloType> hello = null; try { hello = ReceiveHelloMessage( true, true, () => { AddScopes(newScopes); scopesAdded = true; }); } catch (FaultException fault) { if (fault.IsValidOnvifFault("Receiver/Action/TooManyScopes")) { StepPassed(); canAddScopes = false; } else { throw; } } //According to CR26, if device cannot add scopes, consider test as passed. if (canAddScopes) { List <string> currentScopes = new List <string>(ScopesToStringArray(scopes) .Except(oldNonfixedScopes).Concat(newNonfixedScopes).Concat(newScopes)); string reason; Assert(ValidateHelloMessage(hello, currentScopes.ToArray(), out reason), reason, "Hello message validation"); //probe new scopes SoapMessage <WSD.ProbeMatchesType> probeMatch = ProbeDeviceStep(true, newScopes); Assert(ValidateProbeMatchMessage(probeMatch, out reason), reason, Resources.StepValidateProbeMatch_Title); //delete create scopes hello = ReceiveHelloMessage( true, true, () => { RemoveScopes(newScopes); scopesAdded = false; }); Assert(ValidateHelloMessage(hello, currentScopes.Except(newScopes).ToArray(), out reason), reason, "Hello message validation"); //probe deleted scopes InvalidProbeDeviceStep(true, newScopes); } }, (param) => { if (scopesAdded && (newScopes != null)) { RemoveScopes(newScopes); } if (scopesReplaced && oldNonfixedScopes.Count > 0) { if (oldNonfixedScopes.Count > 0) { SetScopes(oldNonfixedScopes.ToArray()); } } }); }
public void DeviceScopesConfigurationTest() { bool scopesAdded = false; string[] newScopes = null; RunTest <string[]>( new Backup <string[]>(() => { return(null); }), () => { //get and validate fixed scopes Scope[] scopes = GetScopes(); string missingScope = DiscoveryUtils.GetMissingMandatoryScope(scopes); Assert(string.IsNullOrEmpty(missingScope), string.Format(Resources.ErrorMissingMandatoryScope_Format, missingScope), "Validating device scopes"); //set fixed scopes fault validation SetFixedScopes(scopes); //add new scopes //begin wait before sending AddScopes, because Hello can be sent by NVT before response to AddScopes newScopes = new string[] { "onvif://www.onvif.org/" + Guid.NewGuid().ToString(), "onvif://www.onvif.org/" + Guid.NewGuid().ToString() }; bool canAddScopes = true; SoapMessage <WSD.HelloType> hello = null; try { hello = ReceiveHelloMessage( true, true, () => { AddScopes(newScopes); scopesAdded = true; }); } catch (FaultException fault) { if (fault.IsValidOnvifFault("Receiver/Action/TooManyScopes")) { StepPassed(); canAddScopes = false; } else { throw; } } //According to CR26, if device cannot add scopes, consider test as passed. if (canAddScopes) { string reason; Assert(ValidateHelloMessage(hello, newScopes, out reason), reason, "Hello message validation"); //probe new scopes SoapMessage <WSD.ProbeMatchesType> probeMatch = ProbeDeviceStep(true, newScopes, null); Assert(ValidateProbeMatchMessage(probeMatch, out reason), reason, Resources.StepValidateProbeMatch_Title); //delete create scopes hello = ReceiveHelloMessage( true, true, () => { RemoveScopes(newScopes); scopesAdded = false; }); Assert(ValidateHelloMessage(hello, null, out reason), reason, "Hello message validation"); //probe deleted scopes InvalidProbeDeviceStep(true, newScopes); } }, (param) => { if (scopesAdded && (newScopes != null)) { RemoveScopes(newScopes); } }); }