Skip to content

Commit

Permalink
Gateway Loadbalancer (#14683)
Browse files Browse the repository at this point in the history
* new branch

* fix

* fix

* fix

* fix

* fix

* try restart json

* replace file

Co-authored-by: matyang222 <matthew.yang@microsoft.com>
  • Loading branch information
matyang22 and matyang222 authored May 18, 2021
1 parent 31029da commit b996748
Show file tree
Hide file tree
Showing 36 changed files with 6,329 additions and 78 deletions.
1 change: 1 addition & 0 deletions src/Accounts/Accounts/AzureRmAlias/Mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,7 @@
"Set-AzLoadBalancerBackendAddressPool": "Set-AzureRmLoadBalancerBackendAddressPool",
"New-AzLoadBalancerBackendAddressPool": "New-AzureRmLoadBalancerBackendAddressPool",
"Remove-AzLoadBalancerBackendAddressPool": "Remove-AzureRmLoadBalancerBackendAddressPool",
"New-AzLoadBalancerBackendAddressPoolTunnelInterfaceConfig": "New-AzureRmLoadBalancerBackendAddressPoolTunnelInterfaceConfig",
"New-AzLoadBalancerBackendAddressConfig": "New-AzureRmLoadBalancerBackendAddressConfig",
"Get-AzLoadBalancerBackendAddressPoolConfig": "Get-AzureRmLoadBalancerBackendAddressPoolConfig",
"Add-AzLoadBalancerBackendAddressPoolConfig": "Add-AzureRmLoadBalancerBackendAddressPoolConfig",
Expand Down
24 changes: 24 additions & 0 deletions src/Network/Network.Test/ScenarioTests/LoadBalancerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,29 @@ public void TestCreateSubresourcesOnEmptyLoadBalancer()
{
TestRunner.RunTestScript("Test-CreateSubresourcesOnEmptyLoadBalancer");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.slbdev)]
public void TestGatewayLoadBalancerProviderOnePool()
{
TestRunner.RunTestScript("Test-GatewayLoadBalancer-ProviderOnePool");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.slbdev)]
public void TestGatewayLoadBalancerProviderTwoPool()
{
TestRunner.RunTestScript("Test-GatewayLoadBalancer-ProviderTwoPool");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.slbdev)]
public void TestGatewayLoadBalancerConsumerLb()
{
TestRunner.RunTestScript("Test-GatewayLoadBalancer-ConsumerLb");
}
}
}
207 changes: 206 additions & 1 deletion src/Network/Network.Test/ScenarioTests/LoadBalancerTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2199,6 +2199,211 @@ function Test-LoadBalancerCRUD-InternalBasicSku
}
}

<#
.SYNOPSIS
Tests Gateway LoadBalancer Provider with one pool.
#>
function Test-GatewayLoadBalancer-ProviderOnePool
{
# Setup
$rgname = Get-ResourceGroupName
$vnetName = Get-ResourceName
$subnetName = Get-ResourceName
$lbName = Get-ResourceName
$frontendName = Get-ResourceName
$backendAddressPoolName = Get-ResourceName
$probeName = Get-ResourceName
$lbruleName = Get-ResourceName
$rglocation = "eastus2euap"
$resourceTypeParent = "Microsoft.Network/loadBalancers"
$location = "eastus2euap"

try
{
# Create the resource group
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval"}

# Create the Virtual Network
$subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 172.20.0.0/24
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 172.20.0.0/16 -Subnet $subnet

# Create LoadBalancer
$frontend = New-AzLoadBalancerFrontendIpConfig -Name $frontendName -Subnet $vnet.Subnets[0]
$tunnelInterface1 = New-AzLoadBalancerBackendAddressPoolTunnelInterfaceConfig -Protocol Vxlan -Type Internal -Port 2000 -Identifier 800
$tunnelInterface2 = New-AzLoadBalancerBackendAddressPoolTunnelInterfaceConfig -Protocol Vxlan -Type External -Port 2001 -Identifier 801
$backendAddressPool = New-AzLoadBalancerBackendAddressPoolConfig -Name $backendAddressPoolName -TunnelInterface $tunnelInterface1, $tunnelInterface2
$probe = New-AzLoadBalancerProbeConfig -Name $probeName -RequestPath healthcheck.aspx -Protocol http -Port 80 -IntervalInSeconds 15 -ProbeCount 2
$lbrule = New-AzLoadBalancerRuleConfig -Name $lbruleName -FrontendIPConfiguration $frontend -BackendAddressPool $backendAddressPool -Probe $probe -Protocol All -FrontendPort 0 -BackendPort 0 -LoadDistribution SourceIP -DisableOutboundSNAT
$actualLb = New-AzLoadBalancer -Name $lbName -ResourceGroupName $rgname -Location $location -FrontendIpConfiguration $frontend -BackendAddressPool $backendAddressPool -Probe $probe -LoadBalancingRule $lbrule -Sku Gateway

$expectedLb = Get-AzLoadBalancer -Name $lbName -ResourceGroupName $rgname

# Verification
Assert-AreEqual $expectedLb.ResourceGroupName $actualLb.ResourceGroupName
Assert-AreEqual $expectedLb.Name $actualLb.Name
Assert-AreEqual $expectedLb.Location $actualLb.Location
Assert-AreEqualObjectProperties $expectedLb.Sku $actualLb.Sku
Assert-AreEqual "Succeeded" $expectedLb.ProvisioningState
Assert-AreEqual 1 @($expectedLb.FrontendIPConfigurations).Count

Assert-AreEqual $frontendName $expectedLb.FrontendIPConfigurations[0].Name
Assert-AreEqual $vnet.Subnets[0].Id $expectedLb.FrontendIPConfigurations[0].Subnet.Id
Assert-NotNull $expectedLb.FrontendIPConfigurations[0].PrivateIpAddress

Assert-AreEqual $backendAddressPoolName $expectedLb.BackendAddressPools[0].Name

Assert-AreEqual 1 @($expectedLb.BackendAddressPools).Count
Assert-AreEqual 2 @($expectedLb.BackendAddressPools[0].TunnelInterfaces).Count

Assert-AreEqual $tunnelInterface1.Protocol $expectedLb.BackendAddressPools[0].TunnelInterfaces[0].Protocol
Assert-AreEqual $tunnelInterface1.Type $expectedLb.BackendAddressPools[0].TunnelInterfaces[0].Type
Assert-AreEqual $tunnelInterface1.Port $expectedLb.BackendAddressPools[0].TunnelInterfaces[0].Port
Assert-AreEqual $tunnelInterface1.Identifier $expectedLb.BackendAddressPools[0].TunnelInterfaces[0].Identifier

Assert-AreEqual $tunnelInterface2.Protocol $expectedLb.BackendAddressPools[0].TunnelInterfaces[1].Protocol
Assert-AreEqual $tunnelInterface2.Type $expectedLb.BackendAddressPools[0].TunnelInterfaces[1].Type
Assert-AreEqual $tunnelInterface2.Port $expectedLb.BackendAddressPools[0].TunnelInterfaces[1].Port
Assert-AreEqual $tunnelInterface2.Identifier $expectedLb.BackendAddressPools[0].TunnelInterfaces[1].Identifier
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Tests Gateway LoadBalancer Provider with two pools.
#>
function Test-GatewayLoadBalancer-ProviderTwoPool
{
# Setup
$rgname = Get-ResourceGroupName
$vnetName = Get-ResourceName
$subnetName = Get-ResourceName
$lbName = Get-ResourceName
$frontendName = Get-ResourceName
$backendAddressPoolName1 = Get-ResourceName
$backendAddressPoolName2 = Get-ResourceName
$probeName = Get-ResourceName
$lbruleName = Get-ResourceName
$rglocation = "eastus2euap"
$resourceTypeParent = "Microsoft.Network/loadBalancers"
$location = "eastus2euap"

try
{
# Create the resource group
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval"}

# Create the Virtual Network
$subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 172.20.0.0/24
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 172.20.0.0/16 -Subnet $subnet

# Create LoadBalancer
$frontend = New-AzLoadBalancerFrontendIpConfig -Name $frontendName -Subnet $vnet.Subnets[0]
$tunnelInterface1 = New-AzLoadBalancerBackendAddressPoolTunnelInterfaceConfig -Protocol Vxlan -Type Internal -Port 2000 -Identifier 800
$tunnelInterface2 = New-AzLoadBalancerBackendAddressPoolTunnelInterfaceConfig -Protocol Vxlan -Type External -Port 2001 -Identifier 801
$backendAddressPool1 = New-AzLoadBalancerBackendAddressPoolConfig -Name $backendAddressPoolName1 -TunnelInterface $tunnelInterface1
$backendAddressPool2 = New-AzLoadBalancerBackendAddressPoolConfig -Name $backendAddressPoolName2 -TunnelInterface $tunnelInterface2
$probe = New-AzLoadBalancerProbeConfig -Name $probeName -RequestPath healthcheck.aspx -Protocol http -Port 80 -IntervalInSeconds 15 -ProbeCount 2
$lbrule = New-AzLoadBalancerRuleConfig -Name $lbruleName -FrontendIPConfiguration $frontend -BackendAddressPool $backendAddressPool1,$backendAddressPool2 -Probe $probe -Protocol All -FrontendPort 0 -BackendPort 0 -LoadDistribution SourceIP -DisableOutboundSNAT

$actualLb = New-AzLoadBalancer -Name $lbName -ResourceGroupName $rgname -Location $location -FrontendIpConfiguration $frontend -Probe $probe -LoadBalancingRule $lbrule -Sku Gateway -BackendAddressPool $backendAddressPool1,$backendAddressPool2

$expectedLb = Get-AzLoadBalancer -Name $lbName -ResourceGroupName $rgname

# Verification
Assert-AreEqual $expectedLb.ResourceGroupName $actualLb.ResourceGroupName
Assert-AreEqual $expectedLb.Name $actualLb.Name
Assert-AreEqual $expectedLb.Location $actualLb.Location
Assert-AreEqualObjectProperties $expectedLb.Sku $actualLb.Sku
Assert-AreEqual "Succeeded" $expectedLb.ProvisioningState
Assert-AreEqual 1 @($expectedLb.FrontendIPConfigurations).Count

Assert-AreEqual $frontendName $expectedLb.FrontendIPConfigurations[0].Name
Assert-AreEqual $vnet.Subnets[0].Id $expectedLb.FrontendIPConfigurations[0].Subnet.Id
Assert-NotNull $expectedLb.FrontendIPConfigurations[0].PrivateIpAddress

Assert-AreEqual 2 @($expectedLb.BackendAddressPools).Count
Assert-AreEqual 1 @($expectedLb.BackendAddressPools[0].TunnelInterfaces).Count
Assert-AreEqual $tunnelInterface1.Protocol $expectedLb.BackendAddressPools[0].TunnelInterfaces[0].Protocol
Assert-AreEqual $tunnelInterface1.Type $expectedLb.BackendAddressPools[0].TunnelInterfaces[0].Type
Assert-AreEqual $tunnelInterface1.Port $expectedLb.BackendAddressPools[0].TunnelInterfaces[0].Port
Assert-AreEqual $tunnelInterface1.Identifier $expectedLb.BackendAddressPools[0].TunnelInterfaces[0].Identifier

Assert-AreEqual 1 @($expectedLb.BackendAddressPools[1].TunnelInterfaces).Count
Assert-AreEqual $tunnelInterface2.Protocol $expectedLb.BackendAddressPools[1].TunnelInterfaces[0].Protocol
Assert-AreEqual $tunnelInterface2.Type $expectedLb.BackendAddressPools[1].TunnelInterfaces[0].Type
Assert-AreEqual $tunnelInterface2.Port $expectedLb.BackendAddressPools[1].TunnelInterfaces[0].Port
Assert-AreEqual $tunnelInterface2.Identifier $expectedLb.BackendAddressPools[1].TunnelInterfaces[0].Identifier
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Tests Gateway LoadBalancer Consumer ref Provider.
#>
function Test-GatewayLoadBalancer-ConsumerLb
{
# Setup Provider
$rgname = Get-ResourceGroupName
$vnetProviderName = Get-ResourceName
$subnetProviderName = Get-ResourceName
$lbProviderName = Get-ResourceName
$frontendProviderName = Get-ResourceName

# Setup Provider
$pipConusmerName = Get-ResourceName
$subnetConsumerName = Get-ResourceName
$lbConsumerName = Get-ResourceName
$frontendConsumerName = Get-ResourceName
$domainNameLabel = Get-ResourceName

$rglocation = Get-ProviderLocation ResourceManagement
$resourceTypeParent = "Microsoft.Network/loadBalancers"
$location = Get-ProviderLocation $resourceTypeParent

try
{
# Create resource group
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval"}

# Create Provider Virtual Network
$subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetProviderName -AddressPrefix 10.0.1.0/24
$vnet = New-AzVirtualNetwork -Name $vnetProviderName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet

# Create Provider LoadBalancer
$frontendProvider = New-AzLoadBalancerFrontendIpConfig -Name $frontendProviderName -Subnet $vnet.Subnets[0]
$lbProvider = New-AzLoadBalancer -Name $lbProviderName -ResourceGroupName $rgname -Location $location -FrontendIpConfiguration $frontendProvider -Sku Gateway

# Create Consumer publicip
$publicipConsumer = New-AzPublicIpAddress -ResourceGroupName $rgname -Name $pipConusmerName -location $location -AllocationMethod Static -DomainNameLabel $domainNameLabel -Sku Standard

# Create Consumer LoadBalancer
$lbConsumer = New-AzLoadBalancer -Name $lbConsumerName -ResourceGroupName $rgname -Location $location -Sku Standard
Add-AzLoadBalancerFrontendIpConfig -GatewayLoadBalancerId $frontendProvider.Id -LoadBalancer $lbConsumer -Name $frontendConsumerName
$lbConsumer = Set-AzLoadBalancer -LoadBalancer $lbConsumer

$expectedLbConsumer = Get-AzLoadBalancer -Name $lbConsumerName -ResourceGroupName $rgname

# Verification
Assert-NotNull $expectedLbConsumer.frontendIpConfigurations
Assert-NotNull $expectedLbConsumer.frontendIpConfigurations[0]
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Tests creating a public Load balancer with standard sku.
Expand Down Expand Up @@ -2650,7 +2855,7 @@ function Test-CreateSubresourcesOnEmptyLoadBalancer

$lb = Add-AzLoadBalancerBackendAddressPoolConfig -Name $poolName -LoadBalancer $lb
$lb = Add-AzLoadBalancerProbeConfig -Name $probeName -LoadBalancer $lb -Port 2000 -IntervalInSeconds 60 -ProbeCount 3 -Protocol Tcp
$lb = Add-AzLoadBalancerRuleConfig -Name $ruleName -LoadBalancer $lb -FrontendIpConfiguration $ipConfig -Protocol Tcp -FrontendPort 1024 -BackendPort 2048
$lb = Add-AzLoadBalancerRuleConfig -Name $ruleName -LoadBalancer $lb -FrontendIPConfigurationId $lb.FrontendIPConfigurations[0].Id -BackendAddressPoolId $lb.BackendAddressPools[0].Id -ProbeId $lb.Probes[0].Id -Protocol Tcp -FrontendPort 82 -BackendPort 83 -IdleTimeoutInMinutes 15 -LoadDistribution SourceIP
$lb = Add-AzLoadBalancerInboundNatRuleConfig -Name $natRuleName -LoadBalancer $lb -FrontendIpConfiguration $ipConfig -FrontendPort 128 -BackendPort 256

# Update load balancer
Expand Down
63 changes: 63 additions & 0 deletions src/Network/Network.Test/ScenarioTests/NetworkInterfaceTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,69 @@ function Test-NetworkInterfaceCRUDUsingId
}
}

<#
.SYNOPSIS
Tests creating new simple public networkinterface.
#>
function Test-NetworkInterface-GatewayLoadBalancerConsumer
{
# Setup
$rgname = Get-ResourceGroupName

$vnetProviderName = Get-ResourceName
$subnetProviderName = Get-ResourceName
$lbProviderName = Get-ResourceName
$frontendProviderName = Get-ResourceName

$vnetConsumerName = Get-ResourceName
$subnetConsumerName = Get-ResourceName
$publicIpConsumerName = Get-ResourceName
$nicConsumerName = Get-ResourceName
$ipconfigConsumerName = Get-ResourceName
$domainNameLabel = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement
$resourceTypeParent = "Microsoft.Network/networkInterfaces"
$location = Get-ProviderLocation $resourceTypeParent

try
{
# Create the resource group
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }

# Create Provider Virtual Network
$subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetProviderName -AddressPrefix 10.0.1.0/24
$vnet = New-AzVirtualNetwork -Name $vnetProviderName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet

# Create Provider LoadBalancer
$frontendProvider = New-AzLoadBalancerFrontendIpConfig -Name $frontendProviderName -Subnet $vnet.Subnets[0]
$lbProvider = New-AzLoadBalancer -Name $lbProviderName -ResourceGroupName $rgname -Location $location -FrontendIpConfiguration $frontendProvider -Sku Gateway

# Create Consumer Virtual Network
$subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetConsumerName -AddressPrefix 10.0.1.0/24
$vnet = New-AzVirtualNetwork -Name $vnetConsumerName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet

# Create Consumer publicip
$publicipConsumer = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpConsumerName -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel

# Create the ipconfiguration
$ipconfig1 = New-AzNetworkInterfaceIpConfig -Name $ipconfigConsumerName -Subnet $vnet.Subnets[0] -PublicIpAddress $publicipConsumer -GatewayLoadBalancerId $frontendProvider.Id

# Create NetworkInterface
$nicConsumer = New-AzNetworkInterface -Name $nicConsumerName -ResourceGroupName $rgname -Location $location -IpConfiguration $ipconfig1 -Tag @{ testtag = "testval" }

# Create NetworkInterface
$expectedNicConsumer = Get-AzNetworkInterface -Name $nicName -ResourceGroupName $rgname

# Verification
Assert-AreEqual $frontendProvider.Id $expectedNicConsumer.ipconfigurations[0].GatewayLoadBalancer
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Tests creating new simple virtualNetwork with static allocation.
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit b996748

Please sign in to comment.