private void Initialize() { m_PlayingControl = new PlayingControl(); ReadSettings(); Settings.Settings.Instance.MessageFilterLevel = 1; Messages.Instance.MessageReceived += new MessageReceivedHandler(MessageReceived); if (Ares.Settings.Settings.Instance.RecentFiles.GetFiles().Count > 0) { OpenProject(Ares.Settings.FolderFactory.CreateFile(Ares.Settings.Settings.Instance.RecentFiles.GetFiles()[0].FilePath), false); } bool foundAddress = false; bool foundIPv4Address = false; String ipv4Address = String.Empty; String ipAddress = String.Empty; foreach (System.Net.IPAddress address in System.Net.Dns.GetHostAddresses(String.Empty)) { //if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) // continue; if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { foundIPv4Address = true; ipv4Address = address.ToString(); } String s = address.ToString(); if (s == Settings.Settings.Instance.IPAddress) { foundAddress = true; ipAddress = s; } else if (!foundAddress) { ipAddress = s; // take first one } } if (!foundAddress && foundIPv4Address) { ipAddress = ipv4Address; // prefer v4 } if (!String.IsNullOrEmpty(ipAddress)) { Settings.Settings.Instance.IPAddress = ipAddress; } else { Toast.MakeText(this, Resource.String.no_ip_address, ToastLength.Long).Show(); return; } m_Network = new Networks(this, Settings.Settings.Instance.UseLegacyNetwork, Settings.Settings.Instance.UseWebNetwork); m_Network.InitConnectionData(); m_Network.StartUdpBroadcast(); m_BroadcastTimer = new System.Timers.Timer(50); m_BroadcastTimer.Elapsed += new System.Timers.ElapsedEventHandler(m_BroadcastTimer_Elapsed); m_BroadcastTimer.Enabled = true; m_Network.ListenForClient(); }
// Ensure VMs for the LB public IEnumerable <IVirtualMachine> EnsureVMs( INetworks networks, IComputeManager computeManager, int count) { // Create a network for the VMs INetwork network = networks.Define("net" + TestId) .WithRegion(Region) .WithNewResourceGroup(GroupName) .WithAddressSpace("10.0.0.0/28") .WithSubnet("subnet1", "10.0.0.0/29") .WithSubnet("subnet2", "10.0.0.8/29") .Create(); // Define an availability set for the VMs var availabilitySetDefinition = computeManager.AvailabilitySets.Define("as" + TestId) .WithRegion(Region) .WithExistingResourceGroup(GroupName) .WithSku(AvailabilitySetSkuTypes.Managed); // Create the requested number of VM definitions string userName = "******" + TestId; List <ICreatable <IVirtualMachine> > vmDefinitions = new List <ICreatable <IVirtualMachine> >(); for (int i = 0; i < count; i++) { string vmName = TestUtilities.GenerateName("vm"); var vm = computeManager.VirtualMachines.Define(vmName) .WithRegion(Region) .WithExistingResourceGroup(GroupName) .WithExistingPrimaryNetwork(network) .WithSubnet(network.Subnets.Values.First().Name) .WithPrimaryPrivateIPAddressDynamic() .WithoutPrimaryPublicIPAddress() .WithPopularLinuxImage(KnownLinuxVirtualMachineImage.UbuntuServer14_04_Lts) .WithRootUsername(userName) .WithRootPassword("Abcdef.123456") .WithNewAvailabilitySet(availabilitySetDefinition) .WithSize(VirtualMachineSizeTypes.StandardA1); vmDefinitions.Add(vm); } var createdVMs = computeManager.VirtualMachines.Create(vmDefinitions.ToArray()); return(createdVMs); }
private int Initialize(PlayerOptions options) { m_BasicSettings = new BasicSettings(); ReadSettings(); if (options.MessageFilterLevel != -1) { Settings.Settings.Instance.MessageFilterLevel = options.MessageFilterLevel; } Messages.Instance.MessageReceived += new MessageReceivedHandler(MessageReceived); if (options.UdpPort != -1) { Settings.Settings.Instance.UdpPort = options.UdpPort; } if (options.LegacyTcpPort > 0) { Settings.Settings.Instance.TcpPort = options.LegacyTcpPort; Settings.Settings.Instance.UseLegacyNetwork = true; } else { Settings.Settings.Instance.UseLegacyNetwork = (options.LegacyTcpPort != -1); } if (options.WebTcpPort != -1) { if (!IsLinux && options.WebTcpPort != Settings.Settings.Instance.WebTcpPort) { String args = String.Format("ChangePort {0} {1}", Settings.Settings.Instance.WebTcpPort, options.WebTcpPort); ChangeSecuritySettings(args); } Settings.Settings.Instance.WebTcpPort = options.WebTcpPort; Settings.Settings.Instance.UseWebNetwork = true; } else { Settings.Settings.Instance.UseWebNetwork = false; } if (options.OutputDevice == 0) { int outputDevice = Settings.Settings.Instance.OutputDeviceIndex; if (outputDevice != -1) { try { m_BassInit.SwitchDevice(outputDevice); } catch (Ares.Playing.BassInitException) { Console.WriteLine(StringResources.DeviceInitError); } } } else { Settings.Settings.Instance.OutputDeviceIndex = options.OutputDevice; } if (!String.IsNullOrEmpty(options.InitialProject)) { if (options.InitialProject.EndsWith(".apkg", StringComparison.InvariantCultureIgnoreCase)) { ImportProject(options.InitialProject, false); } else { OpenProject(options.InitialProject, false); } } else if (Ares.Settings.Settings.Instance.RecentFiles.GetFiles().Count > 0) { OpenProject(Ares.Settings.Settings.Instance.RecentFiles.GetFiles()[0].FilePath, false); } else { Console.WriteLine(StringResources.NoOpenedProject); } bool foundAddress = false; bool foundIPv4Address = false; String ipv4Address = String.Empty; String ipAddress = String.Empty; foreach (System.Net.IPAddress address in System.Net.Dns.GetHostAddresses(String.Empty)) { //if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) // continue; if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { foundIPv4Address = true; ipv4Address = address.ToString(); } String s = address.ToString(); if (s == Settings.Settings.Instance.IPAddress) { foundAddress = true; ipAddress = s; } else if (!foundAddress) { ipAddress = s; // take first one } } if (!foundAddress && foundIPv4Address) { ipAddress = ipv4Address; // prefer v4 } if (!String.IsNullOrEmpty(ipAddress)) { Settings.Settings.Instance.IPAddress = ipAddress; } else { Console.WriteLine(StringResources.NoIpAddress); return(2); } m_Network = new Networks(this, Settings.Settings.Instance.UseLegacyNetwork, Settings.Settings.Instance.UseWebNetwork); m_Network.InitConnectionData(); m_Network.StartUdpBroadcast(); m_BroadcastTimer = new System.Timers.Timer(50); m_BroadcastTimer.Elapsed += new System.Timers.ElapsedEventHandler(m_BroadcastTimer_Elapsed); m_BroadcastTimer.Enabled = true; m_Network.ListenForClient(); return(0); }
public override IApplicationGateway CreateResource(IApplicationGateways resources) { testPips = new List <IPublicIPAddress>(applicationGatewayHelper.EnsurePIPs(resources.Manager.PublicIPAddresses)); networks = resources.Manager.Networks; INetwork vnet = networks.Define("net" + applicationGatewayHelper.TestId) .WithRegion(applicationGatewayHelper.Region) .WithNewResourceGroup(applicationGatewayHelper.GroupName) .WithAddressSpace("10.0.0.0/28") .WithSubnet("subnet1", "10.0.0.0/29") .WithSubnet("subnet2", "10.0.0.8/29") .Create(); Thread creationThread = new Thread(() => { Thread.CurrentThread.IsBackground = true; // Create an application gateway resources.Define(applicationGatewayHelper.AppGatewayName) .WithRegion(applicationGatewayHelper.Region) .WithExistingResourceGroup(applicationGatewayHelper.GroupName) // Request routing rules .DefineRequestRoutingRule("rule80") .FromPrivateFrontend() .FromFrontendHttpPort(80) .ToBackendHttpPort(8080) .ToBackendIPAddress("11.1.1.1") .ToBackendIPAddress("11.1.1.2") .WithCookieBasedAffinity() .Attach() .DefineRequestRoutingRule("rule443") .FromPrivateFrontend() .FromFrontendHttpsPort(443) .WithSslCertificateFromPfxFile(new FileInfo(Path.Combine("Assets", "myTest._pfx"))) .WithSslCertificatePassword("Abc123") .ToBackendHttpConfiguration("config1") .ToBackend("backend1") .Attach() .DefineRequestRoutingRule("rule9000") .FromListener("listener1") .ToBackendHttpConfiguration("config1") .ToBackend("backend1") .Attach() .DefineRequestRoutingRule("ruleRedirect") .FromPrivateFrontend() .FromFrontendHttpsPort(444) .WithSslCertificate("cert1") .WithRedirectConfiguration("redirect1") .Attach() // Additional/explicit backend HTTP setting configs .DefineBackendHttpConfiguration("config1") .WithPort(8081) .WithRequestTimeout(45) .Attach() .DefineBackendHttpConfiguration("config2") .Attach() // Additional/explicit backends .DefineBackend("backend1") .WithIPAddress("11.1.1.3") .WithIPAddress("11.1.1.4") .Attach() .DefineBackend("backend2") .Attach() // Additional/explicit frontend listeners .DefineListener("listener1") .WithPrivateFrontend() .WithFrontendPort(9000) .WithHttp() .Attach() // Additional/explicit certificates .DefineSslCertificate("cert1") .WithPfxFromFile(new FileInfo(Path.Combine("Assets", "myTest2._pfx"))) .WithPfxPassword("Abc123") .Attach() // Authentication certificates .DefineAuthenticationCertificate("auth2") .FromFile(new FileInfo(Path.Combine("Assets", "myTest2.cer"))) .Attach() // Additional/explicit backend HTTP setting configs .DefineBackendHttpConfiguration("config1") .WithPort(8081) .WithRequestTimeout(45) .WithHttps() .WithAuthenticationCertificateFromFile(new FileInfo(Path.Combine("Assets", "myTest.cer"))) .Attach() .DefineBackendHttpConfiguration("config2") .WithPort(8082) .WithHttps() .WithAuthenticationCertificate("auth2") // Add the same cert, so only one should be added .WithAuthenticationCertificateFromFile(new FileInfo(Path.Combine("Assets", "myTest2.cer"))) .Attach() // Redirect configurations .DefineRedirectConfiguration("redirect1") .WithType(ApplicationGatewayRedirectType.Permanent) .WithTargetListener("listener1") .WithPathIncluded() .Attach() .DefineRedirectConfiguration("redirect2") .WithType(ApplicationGatewayRedirectType.Temporary) .WithTargetUrl("http://www.microsoft.com") .WithQueryStringIncluded() .Attach() .WithExistingSubnet(vnet, "subnet1") .WithSize(ApplicationGatewaySkuName.StandardMedium) .WithInstanceCount(2) .Create(); }); // Start creating in a separate thread... creationThread.Start(); // ...But don't wait till the end - not needed for the test, 30 sec should be enough TestHelper.Delay(30 * 1000); // Get the resource as created so far string resourceId = applicationGatewayHelper.CreateResourceId(resources.Manager.SubscriptionId); IApplicationGateway appGateway = resources.GetById(resourceId); Assert.NotNull(appGateway); Assert.Equal(ApplicationGatewayTier.Standard, appGateway.Tier); Assert.Equal(ApplicationGatewaySkuName.StandardMedium, appGateway.Size); Assert.Equal(2, appGateway.InstanceCount); Assert.False(appGateway.IsPublic); Assert.True(appGateway.IsPrivate); Assert.Single(appGateway.IPConfigurations); // Verify redirect configurations Assert.Equal(2, appGateway.RedirectConfigurations.Count); IApplicationGatewayRedirectConfiguration redirect = null; Assert.True(appGateway.RedirectConfigurations.TryGetValue("redirect1", out redirect)); Assert.NotNull(redirect); Assert.Equal(ApplicationGatewayRedirectType.Permanent, redirect.Type); Assert.NotNull(redirect.TargetListener); Assert.Equal("listener1", redirect.TargetListener.Name, true); Assert.Null(redirect.TargetUrl); Assert.True(redirect.IsPathIncluded); Assert.False(redirect.IsQueryStringIncluded); Assert.Single(redirect.RequestRoutingRules); Assert.True(appGateway.RedirectConfigurations.TryGetValue("redirect2", out redirect)); Assert.NotNull(redirect); Assert.Equal(ApplicationGatewayRedirectType.Temporary, redirect.Type); Assert.Null(redirect.TargetListener); Assert.NotNull(redirect.TargetUrl); Assert.Equal("http://www.microsoft.com", redirect.TargetUrl, true); Assert.True(redirect.IsQueryStringIncluded); Assert.False(redirect.IsPathIncluded); // Verify frontend ports Assert.Equal(4, appGateway.FrontendPorts.Count); Assert.NotNull(appGateway.FrontendPortNameFromNumber(80)); Assert.NotNull(appGateway.FrontendPortNameFromNumber(443)); Assert.NotNull(appGateway.FrontendPortNameFromNumber(9000)); Assert.NotNull(appGateway.FrontendPortNameFromNumber(444)); // Verify frontends Assert.Single(appGateway.Frontends); Assert.Empty(appGateway.PublicFrontends); Assert.Single(appGateway.PrivateFrontends); IApplicationGatewayFrontend frontend = appGateway.PrivateFrontends.Values.FirstOrDefault(); Assert.False(frontend.IsPublic); Assert.True(frontend.IsPrivate); // Verify listeners Assert.Equal(4, appGateway.Listeners.Count); IApplicationGatewayListener listener = appGateway.Listeners["listener1"]; Assert.NotNull(listener); Assert.Equal(9000, listener.FrontendPortNumber); Assert.Equal(ApplicationGatewayProtocol.Http, listener.Protocol); Assert.NotNull(listener.Frontend); Assert.True(listener.Frontend.IsPrivate); Assert.False(listener.Frontend.IsPublic); Assert.NotNull(appGateway.ListenerByPortNumber(80)); Assert.NotNull(appGateway.ListenerByPortNumber(443)); Assert.NotNull(appGateway.ListenerByPortNumber(444)); // Verify SSL certificates Assert.Equal(2, appGateway.SslCertificates.Count); Assert.Contains("cert1", appGateway.SslCertificates.Keys); // Verify backend HTTP settings configs Assert.Equal(3, appGateway.BackendHttpConfigurations.Count); IApplicationGatewayBackendHttpConfiguration config = appGateway.BackendHttpConfigurations["config1"]; Assert.NotNull(config); Assert.Equal(8081, config.Port); Assert.Equal(45, config.RequestTimeout); Assert.Single(config.AuthenticationCertificates); var config2 = appGateway.BackendHttpConfigurations["config2"]; Assert.NotNull(config2); // Verify authentication certificates Assert.Equal(2, appGateway.AuthenticationCertificates.Count); var authCert2 = appGateway.AuthenticationCertificates["auth2"]; Assert.NotNull(authCert2); Assert.NotNull(authCert2.Data); var authCert = config.AuthenticationCertificates.Values.FirstOrDefault(); Assert.NotNull(authCert); Assert.Single(config2.AuthenticationCertificates); Assert.Equal(authCert2.Name, config2.AuthenticationCertificates.Values.FirstOrDefault().Name, true); // Verify backends Assert.Equal(3, appGateway.Backends.Count); IApplicationGatewayBackend backend = appGateway.Backends["backend1"]; Assert.NotNull(backend); Assert.Equal(2, backend.Addresses.Count); Assert.True(backend.ContainsIPAddress("11.1.1.3")); Assert.True(backend.ContainsIPAddress("11.1.1.4")); Assert.True(appGateway.Backends.ContainsKey("backend2")); // Verify request routing rules Assert.Equal(4, appGateway.RequestRoutingRules.Count); IApplicationGatewayRequestRoutingRule rule; rule = appGateway.RequestRoutingRules["rule80"]; Assert.NotNull(rule); Assert.Equal(vnet.Id, rule.Listener.Frontend.NetworkId); Assert.Equal(80, rule.FrontendPort); Assert.Equal(8080, rule.BackendPort); Assert.True(rule.CookieBasedAffinity); Assert.Equal(2, rule.BackendAddresses.Count); Assert.True(rule.Backend.ContainsIPAddress("11.1.1.1")); Assert.True(rule.Backend.ContainsIPAddress("11.1.1.2")); rule = appGateway.RequestRoutingRules["rule443"]; Assert.NotNull(rule); Assert.Equal(vnet.Id, rule.Listener.Frontend.NetworkId); Assert.Equal(443, rule.FrontendPort); Assert.Equal(ApplicationGatewayProtocol.Https, rule.FrontendProtocol); Assert.NotNull(rule.SslCertificate); Assert.NotNull(rule.BackendHttpConfiguration); Assert.Equal("config1", rule.BackendHttpConfiguration.Name, true); Assert.NotNull(rule.Backend); Assert.Equal("backend1", rule.Backend.Name, true); rule = appGateway.RequestRoutingRules["rule9000"]; Assert.NotNull(rule); Assert.NotNull(rule.Listener); Assert.Equal("listener1", rule.Listener.Name); Assert.NotNull(rule.Listener.SubnetName); Assert.NotNull(rule.Listener.NetworkId); Assert.NotNull(rule.BackendHttpConfiguration); Assert.Equal("config1", rule.BackendHttpConfiguration.Name, true); Assert.NotNull(rule.Backend); Assert.Equal("backend1", rule.Backend.Name, true); rule = appGateway.RequestRoutingRules["ruleRedirect"]; Assert.NotNull(rule); Assert.NotNull(rule.RedirectConfiguration); Assert.Equal("redirect1", rule.RedirectConfiguration.Name, true); creationThread.Join(); return(appGateway); }
public override ILoadBalancer CreateResource(ILoadBalancers resources) { pips = resources.Manager.PublicIPAddresses; availabilitySets = computeManager.AvailabilitySets; networks = resources.Manager.Networks; var existingVMs = loadBalancerHelper.EnsureVMs(networks, computeManager, 2); var existingPips = loadBalancerHelper.EnsurePIPs(pips); IPublicIPAddress pip0 = resources.Manager.PublicIPAddresses.GetByResourceGroup( loadBalancerHelper.GroupName, loadBalancerHelper.PipNames[0]); // Create a load balancer var lb = resources.Define(loadBalancerHelper.LoadBalancerName) .WithRegion(loadBalancerHelper.Region) .WithExistingResourceGroup(loadBalancerHelper.GroupName) // Load balancing rules .DefineLoadBalancingRule("rule1") .WithProtocol(TransportProtocol.Tcp) // Required .FromExistingPublicIPAddress(pip0) .FromFrontendPort(81) .ToBackend("backend1") .ToBackendPort(82) // Optionals .WithProbe("tcpProbe1") .WithIdleTimeoutInMinutes(10) .WithLoadDistribution(LoadDistribution.SourceIP) .Attach() // Inbound NAT pools .DefineInboundNatPool("natpool1") .WithProtocol(TransportProtocol.Tcp) .FromExistingPublicIPAddress(pip0) .FromFrontendPortRange(2000, 2001) .ToBackendPort(8080) .Attach() // Probes .DefineTcpProbe("tcpProbe1") .WithPort(25) // Required .WithIntervalInSeconds(15) // Optionals .WithNumberOfProbes(5) .Attach() .DefineHttpProbe("httpProbe1") .WithRequestPath("/") // Required .WithIntervalInSeconds(13) // Optionals .WithNumberOfProbes(4) .Attach() // Backends .DefineBackend("backend1") .WithExistingVirtualMachines(new List <IHasNetworkInterfaces>(existingVMs)) .Attach() .Create(); // Verify frontends Assert.Equal(1, lb.Frontends.Count); Assert.Equal(1, lb.PublicFrontends.Count); Assert.Equal(0, lb.PrivateFrontends.Count); var frontend = lb.Frontends.Values.First(); Assert.True(frontend.IsPublic); var publicFrontend = (ILoadBalancerPublicFrontend)frontend; Assert.Equal(pip0.Id, publicFrontend.PublicIPAddressId, ignoreCase: true); // Verify backends Assert.Equal(1, lb.Backends.Count); // Verify probes Assert.Equal(1, lb.HttpProbes.Count); Assert.True(lb.HttpProbes.ContainsKey("httpProbe1")); Assert.Equal(1, lb.TcpProbes.Count); Assert.True(lb.TcpProbes.ContainsKey("tcpProbe1")); // Verify rules Assert.Equal(1, lb.LoadBalancingRules.Count); Assert.True(lb.LoadBalancingRules.ContainsKey("rule1")); var rule = lb.LoadBalancingRules["rule1"]; Assert.NotNull(rule.Backend); Assert.Equal("tcpProbe1", rule.Probe.Name, ignoreCase: true); // Verify inbound NAT pools Assert.True(lb.InboundNatPools.ContainsKey("natpool1")); Assert.Equal(1, lb.InboundNatPools.Count); var inboundNatPool = lb.InboundNatPools["natpool1"]; Assert.Equal(2000, inboundNatPool.FrontendPortRangeStart); Assert.Equal(2001, inboundNatPool.FrontendPortRangeEnd); Assert.Equal(8080, inboundNatPool.BackendPort); return(lb); }
public override ILoadBalancer CreateResource(ILoadBalancers resources) { pips = resources.Manager.PublicIPAddresses; networks = resources.Manager.Networks; availabilitySets = computeManager.AvailabilitySets; var existingVMs = loadBalancerHelper.EnsureVMs(networks, computeManager, 2); Assert.Equal(2, existingVMs.Count()); var existingPips = loadBalancerHelper.EnsurePIPs(pips); var nic1 = existingVMs.ElementAt(0).GetPrimaryNetworkInterface(); var nic2 = existingVMs.ElementAt(1).GetPrimaryNetworkInterface(); IPublicIPAddress pip = resources.Manager.PublicIPAddresses.GetByResourceGroup( loadBalancerHelper.GroupName, loadBalancerHelper.PipNames[0]); // Create a load balancer var lb = resources.Define(loadBalancerHelper.LoadBalancerName) .WithRegion(loadBalancerHelper.Region) .WithExistingResourceGroup(loadBalancerHelper.GroupName) // Load balancing rules .DefineLoadBalancingRule("rule1") .WithProtocol(TransportProtocol.Tcp) // Required .FromExistingPublicIPAddress(pip) .FromFrontendPort(81) .ToBackend("backend1") .ToBackendPort(82) // Optionals .WithProbe("tcpProbe1") .WithIdleTimeoutInMinutes(10) .WithLoadDistribution(LoadDistribution.SourceIP) .Attach() // Inbound NAT rules .DefineInboundNatRule("natrule1") .WithProtocol(TransportProtocol.Tcp) .FromExistingPublicIPAddress(pip) // Implicitly uses the same frontend because the PIP is the same .FromFrontendPort(88) .Attach() // Probes .DefineTcpProbe("tcpProbe1") .WithPort(25) // Required .WithIntervalInSeconds(15) // Optionals .WithNumberOfProbes(5) .Attach() .DefineHttpProbe("httpProbe1") .WithRequestPath("/") // Required .WithIntervalInSeconds(13) // Optionals .WithNumberOfProbes(4) .Attach() .Create(); string backendName = lb.Backends.Values.First().Name; string frontendName = lb.Frontends.Values.First().Name; // Connect NICs explicitly nic1.Update() .WithExistingLoadBalancerBackend(lb, backendName) .WithExistingLoadBalancerInboundNatRule(lb, "natrule1") .Apply(); NetworkInterfaceHelper.PrintNic(nic1); Assert.Equal(nic1.PrimaryIPConfiguration.ListAssociatedLoadBalancerBackends().ElementAt(0) .Name, backendName, ignoreCase: true); Assert.Equal("natrule1", nic1.PrimaryIPConfiguration.ListAssociatedLoadBalancerInboundNatRules().ElementAt(0) .Name, ignoreCase: true); nic2.Update() .WithExistingLoadBalancerBackend(lb, backendName) .Apply(); NetworkInterfaceHelper.PrintNic(nic2); Assert.Equal(nic2.PrimaryIPConfiguration.ListAssociatedLoadBalancerBackends().ElementAt(0) .Name, backendName, ignoreCase: true); // Verify frontends Assert.Single(lb.Frontends.Values); Assert.Single(lb.PublicFrontends.Values); Assert.Empty(lb.PrivateFrontends.Values); Assert.True(lb.Frontends.ContainsKey(frontendName)); var frontend = lb.Frontends[frontendName]; Assert.True(frontend.IsPublic); var publicFrontend = (ILoadBalancerPublicFrontend)frontend; Assert.Equal(pip.Id, publicFrontend.PublicIPAddressId, ignoreCase: true); pip.Refresh(); Assert.Equal(pip.GetAssignedLoadBalancerFrontend().Name, frontendName, ignoreCase: true); // Verify backends Assert.True(lb.Backends.ContainsKey(backendName)); Assert.Single(lb.Backends.Values); // Verify probes Assert.True(lb.HttpProbes.ContainsKey("httpProbe1")); Assert.Single(lb.HttpProbes.Values); Assert.True(lb.TcpProbes.ContainsKey("tcpProbe1")); Assert.Single(lb.TcpProbes.Values); // Verify rules Assert.Single(lb.LoadBalancingRules.Values); Assert.True(lb.LoadBalancingRules.ContainsKey("rule1")); var rule = lb.LoadBalancingRules["rule1"]; Assert.Equal(rule.Backend.Name, backendName, ignoreCase: true); Assert.Equal(rule.Frontend.Name, frontendName, ignoreCase: true); Assert.Equal("tcpProbe1", rule.Probe.Name, ignoreCase: true); // Verify inbound NAT rules Assert.Single(lb.InboundNatRules.Values); Assert.True(lb.InboundNatRules.ContainsKey("natrule1")); var inboundNatRule = lb.InboundNatRules["natrule1"]; Assert.Equal(inboundNatRule.Frontend.Name, frontendName, ignoreCase: true); Assert.Equal(88, inboundNatRule.FrontendPort); Assert.Equal(88, inboundNatRule.BackendPort); return(lb); }
public override IApplicationGateway CreateResource(IApplicationGateways resources) { networks = resources.Manager.Networks; // Create an app gateway resources.Define(applicationGatewayHelper.AppGatewayName) .WithRegion(applicationGatewayHelper.Region) .WithNewResourceGroup(applicationGatewayHelper.GroupName) // Request routing rule .DefineRequestRoutingRule("rule1") .FromPrivateFrontend() .FromFrontendHttpPort(80) .ToBackendHttpPort(8080) .ToBackendIPAddress("11.1.1.1") .ToBackendIPAddress("11.1.1.2") .Attach() .Create(); // Get the resource as created so far string resourceId = applicationGatewayHelper.CreateResourceId(resources.Manager.SubscriptionId); var appGateway = resources.GetById(resourceId); Assert.NotNull(appGateway); Assert.Equal(ApplicationGatewayTier.Standard, appGateway.Tier); Assert.Equal(ApplicationGatewaySkuName.StandardSmall, appGateway.Size); Assert.Equal(1, appGateway.InstanceCount); // Verify frontend ports Assert.Single(appGateway.FrontendPorts.Values); Assert.NotNull(appGateway.FrontendPortNameFromNumber(80)); // Verify frontends Assert.True(appGateway.IsPrivate); Assert.True(!appGateway.IsPublic); Assert.Single(appGateway.Frontends.Values); // Verify listeners Assert.Single(appGateway.Listeners.Values); Assert.NotNull(appGateway.ListenerByPortNumber(80)); // Verify backends Assert.Single(appGateway.Backends.Values); // Verify backend HTTP configs Assert.Single(appGateway.BackendHttpConfigurations.Values); // Verify rules Assert.Single(appGateway.RequestRoutingRules.Values); var rule = appGateway.RequestRoutingRules["rule1"]; Assert.NotNull(rule); Assert.Equal(80, rule.FrontendPort); Assert.Equal(ApplicationGatewayProtocol.Http, rule.FrontendProtocol); Assert.NotNull(rule.Listener); Assert.NotNull(rule.Listener.Frontend); Assert.True(!rule.Listener.Frontend.IsPublic); Assert.True(rule.Listener.Frontend.IsPrivate); Assert.NotNull(rule.Listener.SubnetName); Assert.NotNull(rule.Listener.NetworkId); Assert.Equal(2, rule.BackendAddresses.Count); Assert.NotNull(rule.Backend); Assert.True(rule.Backend.ContainsIPAddress("11.1.1.1")); Assert.True(rule.Backend.ContainsIPAddress("11.1.1.2")); Assert.Equal(8080, rule.BackendPort); return(appGateway); }
public override IApplicationGateway CreateResource(IApplicationGateways resources) { testPips = new List <IPublicIPAddress>(applicationGatewayHelper.EnsurePIPs(resources.Manager.PublicIPAddresses)); networks = resources.Manager.Networks; INetwork vnet = networks.Define("net" + applicationGatewayHelper.TestId) .WithRegion(applicationGatewayHelper.Region) .WithNewResourceGroup(applicationGatewayHelper.GroupName) .WithAddressSpace("10.0.0.0/28") .WithSubnet("subnet1", "10.0.0.0/29") .WithSubnet("subnet2", "10.0.0.8/29") .Create(); Thread creationThread = new Thread(() => { Thread.CurrentThread.IsBackground = true; // Create an application gateway resources.Define(applicationGatewayHelper.AppGatewayName) .WithRegion(applicationGatewayHelper.Region) .WithExistingResourceGroup(applicationGatewayHelper.GroupName) // Request routing rules .DefineRequestRoutingRule("rule80") .FromPrivateFrontend() .FromFrontendHttpPort(80) .ToBackendHttpPort(8080) .ToBackendIPAddress("11.1.1.1") .ToBackendIPAddress("11.1.1.2") .WithCookieBasedAffinity() .Attach() .DefineRequestRoutingRule("rule443") .FromPrivateFrontend() .FromFrontendHttpsPort(443) .WithSslCertificateFromPfxFile(new FileInfo(Path.Combine("Assets", "myTest._pfx"))) .WithSslCertificatePassword("Abc123") .ToBackendHttpConfiguration("config1") .ToBackend("backend1") .Attach() .DefineRequestRoutingRule("rule9000") .FromListener("listener1") .ToBackendHttpConfiguration("config1") .ToBackend("backend1") .Attach() // Additional/explicit backend HTTP setting configs .DefineBackendHttpConfiguration("config1") .WithPort(8081) .WithRequestTimeout(45) .Attach() .DefineBackendHttpConfiguration("config2") .Attach() // Additional/explicit backends .DefineBackend("backend1") .WithIPAddress("11.1.1.3") .WithIPAddress("11.1.1.4") .Attach() .DefineBackend("backend2") .Attach() // Additional/explicit frontend listeners .DefineListener("listener1") .WithPrivateFrontend() .WithFrontendPort(9000) .WithHttp() .Attach() // Additional/explicit certificates .DefineSslCertificate("cert1") .WithPfxFromFile(new FileInfo(Path.Combine("Assets", "myTest2._pfx"))) .WithPfxPassword("Abc123") .Attach() .WithExistingSubnet(vnet, "subnet1") .WithSize(ApplicationGatewaySkuName.StandardMedium) .WithInstanceCount(2) .Create(); }); // Start creating in a separate thread... creationThread.Start(); // ...But don't wait till the end - not needed for the test, 30 sec should be enough TestHelper.Delay(30 * 1000); // Get the resource as created so far string resourceId = applicationGatewayHelper.CreateResourceId(resources.Manager.SubscriptionId); IApplicationGateway appGateway = resources.GetById(resourceId); Assert.NotNull(appGateway); Assert.Equal(ApplicationGatewayTier.Standard, appGateway.Tier); Assert.Equal(ApplicationGatewaySkuName.StandardMedium, appGateway.Size); Assert.Equal(appGateway.InstanceCount, 2); Assert.False(appGateway.IsPublic); Assert.True(appGateway.IsPrivate); Assert.Equal(appGateway.IPConfigurations.Count, 1); // Verify frontend ports Assert.Equal(appGateway.FrontendPorts.Count, 3); Assert.NotNull(appGateway.FrontendPortNameFromNumber(80)); Assert.NotNull(appGateway.FrontendPortNameFromNumber(443)); Assert.NotNull(appGateway.FrontendPortNameFromNumber(9000)); // Verify frontends Assert.Equal(appGateway.Frontends.Count, 1); Assert.Equal(appGateway.PublicFrontends.Count, 0); Assert.Equal(appGateway.PrivateFrontends.Count, 1); IApplicationGatewayFrontend frontend = appGateway.PrivateFrontends.Values.First(); Assert.False(frontend.IsPublic); Assert.True(frontend.IsPrivate); // Verify listeners Assert.Equal(appGateway.Listeners.Count, 3); IApplicationGatewayListener listener = appGateway.Listeners["listener1"]; Assert.NotNull(listener); Assert.Equal(listener.FrontendPortNumber, 9000); Assert.Equal(ApplicationGatewayProtocol.Http, listener.Protocol); Assert.NotNull(listener.Frontend); Assert.True(listener.Frontend.IsPrivate); Assert.False(listener.Frontend.IsPublic); Assert.NotNull(appGateway.ListenerByPortNumber(80)); Assert.NotNull(appGateway.ListenerByPortNumber(443)); // Verify certificates Assert.Equal(appGateway.SslCertificates.Count, 2); Assert.True(appGateway.SslCertificates.ContainsKey("cert1")); // Verify backend HTTP settings configs Assert.Equal(appGateway.BackendHttpConfigurations.Count, 3); IApplicationGatewayBackendHttpConfiguration config = appGateway.BackendHttpConfigurations["config1"]; Assert.NotNull(config); Assert.Equal(config.Port, 8081); Assert.Equal(config.RequestTimeout, 45); Assert.True(appGateway.BackendHttpConfigurations.ContainsKey("config2")); // Verify backends Assert.Equal(appGateway.Backends.Count, 3); IApplicationGatewayBackend backend = appGateway.Backends["backend1"]; Assert.NotNull(backend); Assert.Equal(backend.Addresses.Count, 2); Assert.True(backend.ContainsIPAddress("11.1.1.3")); Assert.True(backend.ContainsIPAddress("11.1.1.4")); Assert.True(appGateway.Backends.ContainsKey("backend2")); // Verify request routing rules Assert.Equal(appGateway.RequestRoutingRules.Count, 3); IApplicationGatewayRequestRoutingRule rule; rule = appGateway.RequestRoutingRules["rule80"]; Assert.NotNull(rule); Assert.Equal(vnet.Id, rule.Listener.Frontend.NetworkId); Assert.Equal(rule.FrontendPort, 80); Assert.Equal(rule.BackendPort, 8080); Assert.True(rule.CookieBasedAffinity); Assert.Equal(rule.BackendAddresses.Count, 2); Assert.True(rule.Backend.ContainsIPAddress("11.1.1.1")); Assert.True(rule.Backend.ContainsIPAddress("11.1.1.2")); rule = appGateway.RequestRoutingRules["rule443"]; Assert.NotNull(rule); Assert.Equal(vnet.Id, rule.Listener.Frontend.NetworkId); Assert.Equal(rule.FrontendPort, 443); Assert.Equal(ApplicationGatewayProtocol.Https, rule.FrontendProtocol); Assert.NotNull(rule.SslCertificate); Assert.NotNull(rule.BackendHttpConfiguration); Assert.Equal(rule.BackendHttpConfiguration.Name, "config1"); Assert.NotNull(rule.Backend); Assert.Equal(rule.Backend.Name, "backend1"); rule = appGateway.RequestRoutingRules["rule9000"]; Assert.NotNull(rule); Assert.NotNull(rule.Listener); Assert.Equal(rule.Listener.Name, "listener1"); Assert.NotNull(rule.Listener.SubnetName); Assert.NotNull(rule.Listener.NetworkId); Assert.NotNull(rule.BackendHttpConfiguration); Assert.Equal(rule.BackendHttpConfiguration.Name, "config1"); Assert.NotNull(rule.Backend); Assert.Equal(rule.Backend.Name, "backend1"); creationThread.Join(); return(appGateway); }