void LogConfiguration(NetworkInterfaceSetConfiguration configuration) { if ((configuration.IPv4 != null) && (configuration.IPv4.EnabledSpecified) && (configuration.IPv4.Enabled)) { if (configuration.IPv4.DHCPSpecified) { LogStepEvent("IPv4 DHCP = " + configuration.IPv4.DHCP); } if ((configuration.IPv4.Manual != null) && (configuration.IPv4.Manual.Count() == 1)) { LogStepEvent("IPv4 Address = " + MyV4String(configuration.IPv4.Manual[0])); } } if ((configuration.IPv6 != null) && (configuration.IPv6.EnabledSpecified) && (configuration.IPv6.Enabled)) { if (configuration.IPv6.DHCPSpecified) { LogStepEvent("IPv6 DHCP = " + configuration.IPv6.DHCP.ToString()); } if (configuration.IPv6.AcceptRouterAdvertSpecified) { LogStepEvent("IPv6 Advert = " + configuration.IPv6.AcceptRouterAdvert); } if ((configuration.IPv6.Manual != null) && (configuration.IPv6.Manual.Count() == 1)) { LogStepEvent("IPv6 Address = " + MyV6String(configuration.IPv6.Manual[0])); } } }
// A.24 - Restore network settings public void RestoreNetworkSettings(string oldServiceAddr, string newServiceAddr, bool restoreEnabled, string intToken) { if (!string.IsNullOrEmpty(oldServiceAddr) && !string.IsNullOrEmpty(newServiceAddr)) { Test.BeginStep("Switching to previous IP address"); Test.LogStepEvent("Old address " + newServiceAddr); Test.LogStepEvent("Selecting " + oldServiceAddr); Test.RaiseNetworkSettingsChangedEvent(oldServiceAddr); ReConnectTo(oldServiceAddr); Test.StepPassed(); } if (restoreEnabled) { NetworkInterfaceSetConfiguration configuration = new NetworkInterfaceSetConfiguration(); configuration.IPv6 = new IPv6NetworkInterfaceSetConfiguration(); configuration.IPv6.Enabled = false; configuration.IPv6.EnabledSpecified = true; SetIPConfigurationInt(intToken, configuration, true); } }
protected bool SetNetworkInterface(string interfaceToken, NetworkInterfaceSetConfiguration configuration) { bool result = Client.SetNetworkInterfaces(interfaceToken, configuration); DoRequestDelay(); return(result); }
NetworkInterface TurnOffDhcpIpv6() { BackupConnection(); NetworkInterface[] interfaces = GetNetworkInterfaces(); BeginStep("Check if DHCP must be turned off"); NetworkInterface ni = null; foreach (NetworkInterface n in interfaces) { if (n.IPv6 == null) { continue; } //if (!n.IPv6.Enabled) continue; if (n.IPv6.Config == null) { continue; } ni = n; break; } if (ni == null) { throw new AssertException("Appropriate network interface not found"); } if (ni.IPv6.Config.DHCP == IPv6DHCPConfiguration.Off) { LogStepEvent("DHCP is OFF"); StepPassed(); return(ni); } StepPassed(); NetworkInterfaceSetConfiguration configuration = new NetworkInterfaceSetConfiguration(); configuration.Enabled = true; configuration.EnabledSpecified = true; configuration.IPv6 = new IPv6NetworkInterfaceSetConfiguration(); configuration.IPv6.Enabled = true; configuration.IPv6.EnabledSpecified = true; configuration.IPv6.DHCP = IPv6DHCPConfiguration.Off; configuration.IPv6.DHCPSpecified = true; if (ni.IPv6.Config.FromDHCP != null && ni.IPv6.Config.FromDHCP.Length > 0) { configuration.IPv6.Manual = ni.IPv6.Config.FromDHCP; } SetIPConfiguration(ni.token, configuration); return(ni); }
public void IPv4StaticIPTest() { NetworkInterface[] originalSettings = null; string token = null; RunTest<NetworkInterface[]>( new Backup<NetworkInterface[]>( () => { return originalSettings = BackupInterfaces(); }), () => { NetworkInterfaceSetConfiguration configuration = new NetworkInterfaceSetConfiguration(); configuration.IPv4 = new IPv4NetworkInterfaceSetConfiguration(); configuration.Enabled = true; configuration.EnabledSpecified = true; configuration.IPv4 = new IPv4NetworkInterfaceSetConfiguration(); configuration.IPv4.Enabled = true; configuration.IPv4.EnabledSpecified = true; configuration.IPv4.DHCP = false; configuration.IPv4.DHCPSpecified = true; configuration.IPv4.Manual = new PrefixedIPv4Address[] { originalSettings.GetAvailableIPv4Address(out token) }; RunNormal("Verifying IPv4 presence", new Action(() => { MyAssert( LogAssertVal(token, "interface"), "No available interface token or they are improperly configured"); })); SetIPConfiguration(token, configuration); NetworkInterface[] currentSettings = GetNetworkInterfaces(); NetworkInterface modified = currentSettings.Where(NI => NI.token == token).FirstOrDefault(); RunNormal("Verifying appliance of IPv4 static settings", new Action(() => { MyAssert( LogLog("Check for interface token = " + token) && LogAssert(modified, "interface") && LogAssert(modified.IPv4, "interface data") && LogAssert(modified.IPv4.Enabled, "IP configuration not enabled") && LogAssert(modified.IPv4.Config, "IP configuration") && LogAssertLog(!modified.IPv4.Config.DHCP, "DHCP {0}applied") && LogAssert(modified.IPv4.Config.Manual, "IP addresses") && #if USE_COLLECTION_COMPARE LogAssertPrefix4(modified.IPv4.Config.Manual, configuration.IPv4.Manual[0]) #else LogAssert(modified.IPv4.Config.Manual.Count() == configuration.IPv4.Manual.Count(), "IP addresses count not equal") && LogAssertLog(modified.IPv4.Config.Manual[0].Address == configuration.IPv4.Manual[0].Address, "IP address {0}applied") && LogAssertLog(modified.IPv4.Config.Manual[0].PrefixLength == configuration.IPv4.Manual[0].PrefixLength, "IP prefix {0}applied") #endif , "Settings not applied", "Settings applied successfully"); }));
string GuessAddress(NetworkInterfaceSetConfiguration configuration) { string SetIP = null; if ((configuration.IPv4 != null) && (configuration.IPv4.EnabledSpecified) && (configuration.IPv4.Enabled)) { if ((configuration.IPv4.Manual != null) && (configuration.IPv4.Manual.Count() == 1)) { SetIP = configuration.IPv4.Manual[0].Address; } } if ((configuration.IPv6 != null) && (configuration.IPv6.EnabledSpecified) && (configuration.IPv6.Enabled)) { if (!BackupIPv6) { return(AddressBackup); } if ((configuration.IPv6.Manual != null) && (configuration.IPv6.Manual.Count() == 1)) { SetIP = "[" + configuration.IPv6.Manual[0].Address + "]"; } } if (string.IsNullOrEmpty(SetIP)) { return(AddressBackup); } string Postfix = "/onvif/device_service"; { string uri = AddressBackup; int pos = uri.IndexOf(']', 8); if (pos > 0) // IPv6 { pos++; } else { pos = uri.IndexOf(':', 8); } if (pos <= 0) { pos = uri.IndexOf('/', 8); } if (pos > 0) { Postfix = uri.Substring(pos); } } return("http://" + SetIP + Postfix); }
/// <summary> /// /// </summary> /// <returns>Original interface</returns> NetworkInterface TurnOnDhcpIpv4() { BackupConnection(); NetworkInterface[] interfaces = GetNetworkInterfaces(); BeginStep("Check if DHCP must be turned on"); NetworkInterface ni = null; foreach (NetworkInterface n in interfaces) { if (n.IPv4 == null) { continue; } if (!n.IPv4.Enabled) { continue; } if (n.IPv4.Config == null) { continue; } ni = n; break; } if (ni == null) { throw new AssertException("Appropriate network interface not found"); } if (ni.IPv4.Config.DHCP) { LogStepEvent("DHCP is ON"); StepPassed(); return(ni); } StepPassed(); NetworkInterfaceSetConfiguration configuration = new NetworkInterfaceSetConfiguration(); configuration.Enabled = true; configuration.EnabledSpecified = true; configuration.IPv4 = new IPv4NetworkInterfaceSetConfiguration(); configuration.IPv4.Enabled = true; configuration.IPv4.EnabledSpecified = true; configuration.IPv4.DHCP = true; configuration.IPv4.DHCPSpecified = true; SetIPConfiguration(ni.token, configuration); return(ni); }
void SetIPInternal(string token, string ip, int prefix) { EnableLogResponse = false; NetworkInterface[] interfaces; try { interfaces = Client.GetNetworkInterfaces(); } catch (Exception exc) { ReportException(exc, "An exception was thrown during getting network interface: "); ReportOperationCompleted(); return; } finally { EnableLogResponse = true; } foreach (NetworkInterface networkInterface in interfaces) { if (networkInterface.token == token) { PrefixedIPv4Address address = new PrefixedIPv4Address(); address.Address = ip; address.PrefixLength = prefix; NetworkInterfaceSetConfiguration nisc = new NetworkInterfaceSetConfiguration(); nisc.IPv4 = new IPv4NetworkInterfaceSetConfiguration(); nisc.IPv4.DHCP = false; nisc.IPv4.DHCPSpecified = false; nisc.IPv4.Enabled = true; nisc.IPv4.EnabledSpecified = true; nisc.IPv4.Manual = new PrefixedIPv4Address[1]; nisc.IPv4.Manual[0] = address; nisc.MTU = networkInterface.Info.MTU; nisc.MTUSpecified = true; nisc.Link = networkInterface.Link.AdminSettings; nisc.Enabled = true; nisc.EnabledSpecified = true; Client.SetNetworkInterfaces(token, nisc); return; } } throw new Exception(string.Format("Network interface matching Token \"{0}\" not found", token)); }
protected bool SetNetworkInterface(string interfaceToken, NetworkInterfaceSetConfiguration configuration) { #if true return(Client.SetNetworkInterfaces(interfaceToken, configuration)); #else bool rebootNeeded = false; RunStep(() => { rebootNeeded = Client.SetNetworkInterfaces(interfaceToken, configuration); } , "Set network interfaces"); return(rebootNeeded); #endif }
protected void RestoreNetworkInterface(string interfaceToken, NetworkInterface networkInterface) { NetworkInterfaceSetConfiguration configuration = new NetworkInterfaceSetConfiguration(); configuration.Enabled = networkInterface.Enabled; configuration.EnabledSpecified = true; //configuration.Extension if (networkInterface.IPv4 != null) { configuration.IPv4 = new IPv4NetworkInterfaceSetConfiguration(); configuration.IPv4.DHCP = networkInterface.IPv4.Config.DHCP; configuration.IPv4.DHCPSpecified = true; configuration.IPv4.Enabled = networkInterface.IPv4.Enabled; configuration.IPv4.EnabledSpecified = true; configuration.IPv4.Manual = networkInterface.IPv4.Config.Manual; } if (networkInterface.IPv6 != null) { configuration.IPv6 = new IPv6NetworkInterfaceSetConfiguration(); configuration.IPv6.Enabled = networkInterface.IPv6.Enabled; configuration.IPv6.EnabledSpecified = true; if (networkInterface.IPv6.Config != null) { configuration.IPv6.AcceptRouterAdvert = networkInterface.IPv6.Config.AcceptRouterAdvert; configuration.IPv6.AcceptRouterAdvertSpecified = networkInterface.IPv6.Config.AcceptRouterAdvertSpecified; //if (networkInterface.IPv6.Config.DHCP != null) //{ configuration.IPv6.DHCP = networkInterface.IPv6.Config.DHCP; configuration.IPv6.DHCPSpecified = true; //} configuration.IPv6.Manual = networkInterface.IPv6.Config.Manual; } } //configuration.Link = networkInterface.Link; SetIPConfigurationInt(interfaceToken, configuration, true); }
public OnvifSetNetworkInterfaces(string uri, string userName, string password, string token, NetworkInterfaceSetConfiguration networkConfiguration) : base(uri, userName, password) { Token = token; NetworkConfiguration = networkConfiguration; }
void SetIPConfigurationInt(string interfaceToken, NetworkInterfaceSetConfiguration configuration, bool restore) { bool rebootNeeded = false; SoapMessage <WSD.HelloType> hello = null; try { hello = ReceiveHelloMessage( false, true, new Action(() => { Test.BeginStep(restore ? "Restore network settings" : "Set network interface"); if (!restore) { Test.LogStepEvent("interface token = " + interfaceToken); LogConfiguration(configuration); } rebootNeeded = SetNetworkInterface(interfaceToken, configuration); //if (!restore) { Test.LogStepEvent("reboot need = " + rebootNeeded); } Test.StepPassed(); if (rebootNeeded) { SystemReboot(); } })); } catch (AssertException) { // Assert: something wrong with receiving message (see DeviceDiscoveryTest.ReceiveMessageInternal) // SetNetworkInterface and SystemReboot don't throw AssertException. if (!rebootNeeded) { Test.LogStepEvent("Warning: no Hello within timeout"); StepPassed(); if (restore) { RaiseNetworkSettingsChangedEvent(AddressBackup); RestoreConnection(AddressBackup); return; } // should not occur, hack if (AddressBackup == null) { return; } BeginStep("No Hello - guessing right address"); string newServiceAddr = GuessAddress(configuration); Test.LogStepEvent("Selecting " + newServiceAddr); // raise event that network settings changed RaiseNetworkSettingsChangedEvent(newServiceAddr); ReConnectTo(newServiceAddr); StepPassed(); return; // no strict requirement for hello in this case } throw; } // catch if (!rebootNeeded) { if (hello == null) { return; // no strict requirement for hello in this case } } // no types verification - good for 2.1 RunNormal("Verifying Hello message", new Action(() => { MyAssert( LogAssert(hello, "hello") && LogAssert(hello.Object, "hello content") && LogAssert(hello.Object.EndpointReference, "hello endpoint") && LogAssert(hello.Object.EndpointReference.Address, "hello endpoint address") && LogAssert(hello.Object.EndpointReference.Address.Value, "hello endpoint address value") && LogLog("Endpoint Address = " + hello.Object.EndpointReference.Address.Value) && LogAssert(hello.Object.XAddrs, "hello service address(es) value") && LogLog("Service Address(es) = " + hello.Object.XAddrs), "Hello not verified", "Hello verified successfully"); })); { BeginStep("Identifying right address"); if (AddressBackup != null) { Test.LogStepEvent("Old address " + AddressBackup); } string[] addresses = hello.Object.XAddrs.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string newServiceAddr = AddressBackup; int count = 0; foreach (string s in addresses) { int c = FindPrefixLength(s, AddressBackup); if (c > count) { newServiceAddr = s; count = c; } } Test.LogStepEvent("Selecting " + newServiceAddr); // raise event that network settings changed RaiseNetworkSettingsChangedEvent(newServiceAddr); ReConnectTo(newServiceAddr); StepPassed(); } }
NetworkInterface TurnOffDhcpIpv4() { BackupConnection(); NetworkInterface[] interfaces = GetNetworkInterfaces(); BeginStep("Check if DHCP must be turned off"); NetworkInterface ni = null; foreach (NetworkInterface n in interfaces) { if (n.IPv4 == null) { continue; } //if (!n.IPv4.Enabled) continue; if (n.IPv4.Config == null) { continue; } ni = n; break; } if (ni == null) { throw new AssertException("Appropriate network interface not found"); } if (!ni.IPv4.Config.DHCP) { LogStepEvent("DHCP is OFF"); StepPassed(); return(ni); } else { if (ni.IPv4.Config.FromDHCP == null || string.IsNullOrEmpty(ni.IPv4.Config.FromDHCP.Address)) { throw new AssertException("IP address not returned from the DUT"); } } StepPassed(); NetworkInterfaceSetConfiguration configuration = new NetworkInterfaceSetConfiguration(); configuration.IPv4 = new IPv4NetworkInterfaceSetConfiguration(); configuration.Enabled = true; configuration.EnabledSpecified = true; configuration.IPv4.Enabled = true; configuration.IPv4.EnabledSpecified = true; configuration.IPv4.DHCP = false; configuration.IPv4.DHCPSpecified = true; configuration.IPv4.Manual = new PrefixedIPv4Address[] { Extensions.NextAddress(ni.IPv4.Config.FromDHCP) }; SetIPConfiguration(ni.token, configuration); return(ni); }
protected void SetIPConfiguration(string interfaceToken, NetworkInterfaceSetConfiguration configuration) { SetIPConfigurationInt(interfaceToken, configuration, false); }
void EnableIPv6(string intToken, ref string oldServiceAddr, ref string newServiceAddr, out bool restoreEnabled) { NetworkInterfaceSetConfiguration configuration = new NetworkInterfaceSetConfiguration(); configuration.IPv6 = new IPv6NetworkInterfaceSetConfiguration(); configuration.IPv6.Enabled = true; configuration.IPv6.EnabledSpecified = true; SetIPConfiguration(intToken, configuration); // verify if IPv6 settings were applied NetworkInterface[] currentSettings = GetNetworkInterfaces(); NetworkInterface modified = currentSettings.Where(NI => NI.token == intToken).FirstOrDefault(); Test.Assert(modified.IPv6 != null && modified.IPv6.Enabled, "IPv6 settings were not applied", "Verifying appliance of IPv6 settings"); restoreEnabled = true; if (modified.IPv6.Config.DHCP == IPv6DHCPConfiguration.Off) { // Manual tag exists if (modified.IPv6.Config.Manual != null && modified.IPv6.Config.Manual.Length != 0 && !string.IsNullOrEmpty(modified.IPv6.Config.Manual[0].Address)) { string IPv6 = modified.IPv6.Config.Manual[0].Address; SelectIPv6(ref oldServiceAddr, ref newServiceAddr, IPv6); } // LinkLocal tag exists else if (modified.IPv6.Config.LinkLocal != null && modified.IPv6.Config.LinkLocal.Length != 0 && !string.IsNullOrEmpty(modified.IPv6.Config.LinkLocal[0].Address)) { string IPv6 = modified.IPv6.Config.LinkLocal[0].Address; SelectIPv6(ref oldServiceAddr, ref newServiceAddr, IPv6); } else { Test.Assert(false, "Manual or LinkLocal IPv6 addresses were not found", "Searching for Manual or LinkLocal IPv6 address"); } } else { // FromDHCP tag exists if (modified.IPv6.Config.FromDHCP != null && modified.IPv6.Config.FromDHCP.Length != 0 && !string.IsNullOrEmpty(modified.IPv6.Config.FromDHCP[0].Address)) { string IPv6 = modified.IPv6.Config.FromDHCP[0].Address; SelectIPv6(ref oldServiceAddr, ref newServiceAddr, IPv6); } // LinkLocal tag exists else if (modified.IPv6.Config.LinkLocal != null && modified.IPv6.Config.LinkLocal.Length != 0 && !string.IsNullOrEmpty(modified.IPv6.Config.LinkLocal[0].Address)) { string IPv6 = modified.IPv6.Config.LinkLocal[0].Address; SelectIPv6(ref oldServiceAddr, ref newServiceAddr, IPv6); } else { Test.Assert(false, "FromDHCP or LinkLocal IPv6 addresses were not found", "Searching for Manual or LinkLocal IPv6 address"); } } }
public override bool SetNetworkInterfaces(string InterfaceToken, NetworkInterfaceSetConfiguration NetworkInterface) { throw new NotImplementedException(); }
public void SetNetworkInterfaceInvalidIPv6Test() { RunTest(() => { NetworkInterface[] interfaces = GetNetworkInterfaces(); Assert(interfaces != null && interfaces.Length > 0, "No interfaces returned from the DUT", "Check that the DUT returned current interfaces"); string interfaceToken = null; foreach (NetworkInterface ni in interfaces) { if (ni.IPv6 != null) { interfaceToken = ni.token; break; } } Assert(interfaceToken != null, "No appropriate interface found", "Check that an interface with IPv6 configuration is presented"); NetworkInterfaceSetConfiguration configuration = new NetworkInterfaceSetConfiguration(); configuration.IPv6 = new IPv6NetworkInterfaceSetConfiguration(); configuration.IPv6.Enabled = true; configuration.IPv6.EnabledSpecified = true; string invalidAddress = "FF02:1"; configuration.IPv6.Manual = new PrefixedIPv6Address[] { new PrefixedIPv6Address() { Address = invalidAddress } }; RunStep(() => { Client.SetNetworkInterfaces(interfaceToken, configuration); }, "Set Network Interfaces - negative test", "Sender/InvalidArgVal/InvalidIPv6Address", true); DoRequestDelay(); interfaces = GetNetworkInterfaces(); Assert(interfaces != null && interfaces.Length > 0, "No interfaces returned from the DUT", "Check that the DUT returned current interfaces"); NetworkInterface modifiedInterface = interfaces.Where(NI => NI.token == interfaceToken).FirstOrDefault(); Assert(modifiedInterface != null, string.Format("Interfaces with token = '{0}' not found", interfaceToken), string.Format("Check if an interface with token = '{0}' is presented", interfaceToken)); BeginStep(string.Format("Check that interface with token '{0}' has not been changed", interfaceToken)); bool passed = false; if (modifiedInterface.IPv6 == null) { LogStepEvent("IPv6 configuration not found"); } else { if ((modifiedInterface.IPv6.Config != null) && (modifiedInterface.IPv6.Config.Manual != null) && (modifiedInterface.IPv6.Config.Manual.Where(A => A.Address == invalidAddress).FirstOrDefault() != null)) { LogStepEvent(string.Format("Invalid IP address {0} is present in the interface configuration", invalidAddress)); } else { passed = true; } } if (!passed) { throw new AssertException("Interface has been changed"); } StepPassed(); }); }
bool IOnVifDevice.SetNetworkInterfaces(string InterfaceToken, NetworkInterfaceSetConfiguration NetworkInterface) { throw new NotImplementedException(); }