Skip to content

Commit 58aee42

Browse files
authored
Enable connection tracking (#27076)
1 parent a8680b4 commit 58aee42

12 files changed

+4024
-71
lines changed

src/Network/Network.Test/ScenarioTests/LoadBalancerTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,5 +328,13 @@ public void TestLoadBalancerInEdgeZone()
328328
{
329329
TestRunner.RunTestScript("Test-LoadBalancerInEdgeZone");
330330
}
331+
332+
[Fact]
333+
[Trait(Category.AcceptanceType, Category.CheckIn)]
334+
[Trait(Category.Owner, NrpTeamAlias.slbdev)]
335+
public void TestLoadBalancerCRUDEnableConnectionTracking()
336+
{
337+
TestRunner.RunTestScript("Test-LoadBalancerCRUD-EnableConnectionTracking");
338+
}
331339
}
332340
}

src/Network/Network.Test/ScenarioTests/LoadBalancerTests.ps1

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,126 @@ function Test-LoadBalancerCRUD-PublicTcpReset
217217
}
218218
}
219219

220+
<#
221+
.SYNOPSIS
222+
Tests creating a public Load balancer with EnableConnectionTracking for lb rule.
223+
#>
224+
function Test-LoadBalancerCRUD-EnableConnectionTracking
225+
{
226+
# Setup
227+
$rgname = Get-ResourceGroupName
228+
$vnetName = Get-ResourceName
229+
$subnetName = Get-ResourceName
230+
$publicIpName = Get-ResourceName
231+
$domainNameLabel = Get-ResourceName
232+
$lbName = Get-ResourceName
233+
$frontendName = Get-ResourceName
234+
$backendAddressPoolName = Get-ResourceName
235+
$probeName = Get-ResourceName
236+
$inboundNatRuleName = Get-ResourceName
237+
$lbruleName = Get-ResourceName
238+
$lbruleName2 = Get-ResourceName
239+
$lbruleName3 = Get-ResourceName
240+
$rglocation = Get-ProviderLocation ResourceManagement
241+
$resourceTypeParent = "Microsoft.Network/loadBalancers"
242+
$location = Get-ProviderLocation $resourceTypeParent
243+
244+
245+
try
246+
{
247+
# Create the resource group
248+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval"}
249+
250+
# Create the Virtual Network
251+
$subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24
252+
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
253+
254+
# Create the publicip
255+
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Static -DomainNameLabel $domainNameLabel -Sku Standard
256+
257+
# Create LoadBalancer
258+
$frontend = New-AzLoadBalancerFrontendIpConfig -Name $frontendName -PublicIpAddress $publicip
259+
$backendAddressPool = New-AzLoadBalancerBackendAddressPoolConfig -Name $backendAddressPoolName
260+
$probe = New-AzLoadBalancerProbeConfig -Name $probeName -RequestPath healthcheck.aspx -Protocol https -Port 80 -IntervalInSeconds 15 -ProbeCount 2 -ProbeThreshold 2
261+
$lbrule = New-AzLoadBalancerRuleConfig -Name $lbruleName -FrontendIPConfiguration $frontend -BackendAddressPool $backendAddressPool -Probe $probe -Protocol Udp -FrontendPort 80 -BackendPort 80 -IdleTimeoutInMinutes 15 -EnableFloatingIP -EnableTcpReset -LoadDistribution SourceIP -DisableOutboundSNAT -EnableConnectionTracking
262+
$actualLb = New-AzLoadBalancer -Name $lbName -ResourceGroupName $rgname -Location $location -FrontendIpConfiguration $frontend -BackendAddressPool $backendAddressPool -Probe $probe -InboundNatRule $inboundNatRule -LoadBalancingRule $lbrule -Sku Standard
263+
264+
$expectedLb = Get-AzLoadBalancer -Name $lbName -ResourceGroupName $rgname
265+
266+
# Verification
267+
Assert-AreEqual $expectedLb.ResourceGroupName $actualLb.ResourceGroupName
268+
Assert-AreEqual $expectedLb.Name $actualLb.Name
269+
Assert-AreEqual $expectedLb.Location $actualLb.Location
270+
Assert-AreEqualObjectProperties $expectedLb.Sku $actualLb.Sku
271+
Assert-AreEqual "Succeeded" $expectedLb.ProvisioningState
272+
Assert-NotNull $expectedLb.ResourceGuid
273+
Assert-AreEqual 1 @($expectedLb.FrontendIPConfigurations).Count
274+
275+
Assert-AreEqual $frontendName $expectedLb.FrontendIPConfigurations[0].Name
276+
Assert-AreEqual $publicip.Id $expectedLb.FrontendIPConfigurations[0].PublicIpAddress.Id
277+
Assert-Null $expectedLb.FrontendIPConfigurations[0].PrivateIpAddress
278+
279+
Assert-AreEqual $backendAddressPoolName $expectedLb.BackendAddressPools[0].Name
280+
281+
Assert-AreEqual $probeName $expectedLb.Probes[0].Name
282+
Assert-AreEqual $probe.RequestPath $expectedLb.Probes[0].RequestPath
283+
Assert-AreEqual "https" $expectedLb.Probes[0].Protocol
284+
Assert-AreEqual $probe.ProbeThreshold $expectedLb.Probes[0].ProbeThreshold
285+
286+
Assert-AreEqual $lbruleName $expectedLb.LoadBalancingRules[0].Name
287+
Assert-AreEqual $expectedLb.FrontendIPConfigurations[0].Id $expectedLb.LoadBalancingRules[0].FrontendIPConfiguration.Id
288+
Assert-AreEqual $expectedLb.BackendAddressPools[0].Id $expectedLb.LoadBalancingRules[0].BackendAddressPool.Id
289+
Assert-AreEqual true $expectedLb.LoadBalancingRules[0].EnableConnectionTracking
290+
291+
# List
292+
$list = Get-AzLoadBalancer -ResourceGroupName $rgname
293+
Assert-AreEqual 1 @($list).Count
294+
Assert-AreEqual $expectedLb.Etag $list[0].Etag
295+
Assert-AreEqualObjectProperties $expectedLb.Sku $list[0].Sku
296+
Assert-AreEqual $expectedLb.FrontendIPConfigurations[0].Etag $list[0].FrontendIPConfigurations[0].Etag
297+
Assert-AreEqual $expectedLb.BackendAddressPools[0].Etag $list[0].BackendAddressPools[0].Etag
298+
Assert-AreEqual $expectedLb.InboundNatRules[0].Etag $list[0].InboundNatRules[0].Etag
299+
Assert-AreEqual $expectedLb.Probes[0].Etag $list[0].Probes[0].Etag
300+
Assert-AreEqual $expectedLb.LoadBalancingRules[0].Etag $list[0].LoadBalancingRules[0].Etag
301+
302+
# Test Set Command
303+
$expectedLb | Set-AzLoadBalancerRuleConfig -Name $lbruleName -FrontendIPConfiguration $frontend -BackendAddressPool $backendAddressPool -Probe $probe -Protocol Udp -FrontendPort 80 -BackendPort 80 -IdleTimeoutInMinutes 15 -EnableFloatingIP -EnableTcpReset -LoadDistribution SourceIP -DisableOutboundSNAT
304+
$expectedLb | Set-AzLoadBalancer
305+
306+
$expectedLb = Get-AzLoadBalancer -Name $lbName -ResourceGroupName $rgname
307+
Assert-AreEqual false $expectedLb.LoadBalancingRules[0].EnableConnectionTracking
308+
309+
$expectedLb | Set-AzLoadBalancerRuleConfig -Name $lbruleName -FrontendIPConfiguration $frontend -BackendAddressPool $backendAddressPool -Probe $probe -Protocol Udp -FrontendPort 80 -BackendPort 80 -IdleTimeoutInMinutes 15 -EnableFloatingIP -EnableTcpReset -LoadDistribution SourceIP -DisableOutboundSNAT -EnableConnectionTracking
310+
$expectedLb | Set-AzLoadBalancer
311+
312+
$expectedLb = Get-AzLoadBalancer -Name $lbName -ResourceGroupName $rgname
313+
Assert-AreEqual true $expectedLb.LoadBalancingRules[0].EnableConnectionTracking
314+
315+
# Test Add Command
316+
$expectedLb | Add-AzLoadBalancerRuleConfig -Name $lbruleName2 -FrontendIPConfiguration $frontend -BackendAddressPool $backendAddressPool -Probe $probe -Protocol Udp -FrontendPort 81 -BackendPort 81 -IdleTimeoutInMinutes 15 -EnableFloatingIP -EnableTcpReset -LoadDistribution SourceIP -DisableOutboundSNAT -EnableConnectionTracking
317+
$expectedLb | Set-AzLoadBalancer
318+
$expectedLb = Get-AzLoadBalancer -Name $lbName -ResourceGroupName $rgname
319+
Assert-AreEqual true $expectedLb.LoadBalancingRules[1].EnableConnectionTracking
320+
321+
$expectedLb | Add-AzLoadBalancerRuleConfig -Name $lbruleName3 -FrontendIPConfiguration $frontend -BackendAddressPool $backendAddressPool -Probe $probe -Protocol Udp -FrontendPort 82 -BackendPort 82 -IdleTimeoutInMinutes 15 -EnableFloatingIP -EnableTcpReset -LoadDistribution SourceIP -DisableOutboundSNAT
322+
$expectedLb | Set-AzLoadBalancer
323+
$expectedLb = Get-AzLoadBalancer -Name $lbName -ResourceGroupName $rgname
324+
Assert-AreEqual false $expectedLb.LoadBalancingRules[2].EnableConnectionTracking
325+
326+
# Delete
327+
$deleteLb = Remove-AzLoadBalancer -Name $lbName -ResourceGroupName $rgname -PassThru -Force
328+
Assert-AreEqual true $deleteLb
329+
330+
$list = Get-AzLoadBalancer -ResourceGroupName $rgname
331+
Assert-AreEqual 0 @($list).Count
332+
}
333+
finally
334+
{
335+
# Cleanup
336+
Clean-ResourceGroup $rgname
337+
}
338+
}
339+
220340
<#
221341
.SYNOPSIS
222342
Tests creating an internal Load balancer with dynamic ip.

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.LoadBalancerTests/TestLoadBalancerCRUDEnableConnectionTracking.json

Lines changed: 3699 additions & 0 deletions
Large diffs are not rendered by default.

src/Network/Network/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
--->
2020

2121
## Upcoming Release
22+
* Added property "EnableConnectionTracking" to Load Balancing Rule, as well as support for it for the following cmdlets:
23+
- `Add-AzLoadBalancerRuleConfig`
24+
- `New-AzLoadBalancerRuleConfig`
25+
- `Set-AzLoadBalancerRuleConfig`
2226
* Added cmdlet for migration of basic IP based deployment to Standard IP based VMSS deployments for VirtualNetworkGateways
2327
- `New-AzVirtualNetworkGatewayMigrationParameter`
2428
- `Invoke-AzVirtualNetworkGatewayPrepareMigration`

src/Network/Network/LoadBalancer/LoadBalancerRule/AddAzureRmLoadBalancerRuleConfigCommand.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public partial class AddAzureRmLoadBalancerRuleConfigCommand : NetworkBaseCmdlet
9494
HelpMessage = "Configures SNAT for the VMs in the backend pool to use the publicIP address specified in the frontend of the load balancing rule.")]
9595
public SwitchParameter DisableOutboundSNAT { get; set; }
9696

97+
[Parameter(
98+
Mandatory = false,
99+
HelpMessage = "Configures SNAT for the VMs in the backend pool to use the publicIP address specified in the frontend of the load balancing rule.")]
100+
public SwitchParameter EnableConnectionTracking { get; set; }
101+
97102
[Parameter(
98103
Mandatory = false,
99104
ParameterSetName = "SetByResourceId",
@@ -184,6 +189,7 @@ public override void Execute()
184189
vLoadBalancingRules.EnableFloatingIP = this.EnableFloatingIP;
185190
vLoadBalancingRules.EnableTcpReset = this.EnableTcpReset;
186191
vLoadBalancingRules.DisableOutboundSNAT = this.DisableOutboundSNAT;
192+
vLoadBalancingRules.EnableConnectionTracking = this.EnableConnectionTracking;
187193
vLoadBalancingRules.Name = this.Name;
188194
if (!string.IsNullOrEmpty(this.FrontendIpConfigurationId))
189195
{

src/Network/Network/LoadBalancer/LoadBalancerRule/NewAzureRmLoadBalancerRuleConfigCommand.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ public partial class NewAzureRmLoadBalancerRuleConfigCommand : NetworkBaseCmdlet
8787
HelpMessage = "Configures SNAT for the VMs in the backend pool to use the publicIP address specified in the frontend of the load balancing rule.")]
8888
public SwitchParameter DisableOutboundSNAT { get; set; }
8989

90+
[Parameter(
91+
Mandatory = false,
92+
HelpMessage = "Configures SNAT for the VMs in the backend pool to use the publicIP address specified in the frontend of the load balancing rule.")]
93+
public SwitchParameter EnableConnectionTracking { get; set; }
94+
9095
[Parameter(
9196
Mandatory = false,
9297
ParameterSetName = "SetByResourceId",
@@ -164,6 +169,7 @@ public override void Execute()
164169
vLoadBalancingRules.EnableFloatingIP = this.EnableFloatingIP;
165170
vLoadBalancingRules.EnableTcpReset = this.EnableTcpReset;
166171
vLoadBalancingRules.DisableOutboundSNAT = this.DisableOutboundSNAT;
172+
vLoadBalancingRules.EnableConnectionTracking = this.EnableConnectionTracking;
167173
vLoadBalancingRules.Name = this.Name;
168174
if (!string.IsNullOrEmpty(this.FrontendIpConfigurationId))
169175
{

src/Network/Network/LoadBalancer/LoadBalancerRule/SetAzureRmLoadBalancerRuleConfigCommand.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public partial class SetAzureRmLoadBalancerRuleConfigCommand : NetworkBaseCmdlet
9494
HelpMessage = "Configures SNAT for the VMs in the backend pool to use the publicIP address specified in the frontend of the load balancing rule.")]
9595
public SwitchParameter DisableOutboundSNAT { get; set; }
9696

97+
[Parameter(
98+
Mandatory = false,
99+
HelpMessage = "Configures SNAT for the VMs in the backend pool to use the publicIP address specified in the frontend of the load balancing rule.")]
100+
public SwitchParameter EnableConnectionTracking { get; set; }
101+
97102
[Parameter(
98103
Mandatory = false,
99104
ParameterSetName = "SetByResourceId",
@@ -179,6 +184,7 @@ public override void Execute()
179184
vLoadBalancingRules.EnableFloatingIP = this.EnableFloatingIP;
180185
vLoadBalancingRules.EnableTcpReset = this.EnableTcpReset;
181186
vLoadBalancingRules.DisableOutboundSNAT = this.DisableOutboundSNAT;
187+
vLoadBalancingRules.EnableConnectionTracking = this.EnableConnectionTracking;
182188
vLoadBalancingRules.Name = this.Name;
183189
if (!string.IsNullOrEmpty(this.FrontendIpConfigurationId))
184190
{

src/Network/Network/Models/PSLoadBalancingRule.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public partial class PSLoadBalancingRule : PSChildResource
4747
public bool? DisableOutboundSNAT { get; set; }
4848
[JsonProperty(Order = 1)]
4949
[Ps1Xml(Target = ViewControl.Table)]
50+
public bool? EnableConnectionTracking { get; set; }
51+
[JsonProperty(Order = 1)]
52+
[Ps1Xml(Target = ViewControl.Table)]
5053
public string ProvisioningState { get; set; }
5154
[JsonProperty(Order = 1)]
5255
public PSResourceId FrontendIPConfiguration { get; set; }

src/Network/Network/Network.generated.format.ps1xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5940,6 +5940,10 @@
59405940
<Alignment>Left</Alignment>
59415941
<Label>DisableOutboundSNAT</Label>
59425942
</TableColumnHeader>
5943+
<TableColumnHeader>
5944+
<Alignment>Left</Alignment>
5945+
<Label>EnableConnectionTracking</Label>
5946+
</TableColumnHeader>
59435947
<TableColumnHeader>
59445948
<Alignment>Left</Alignment>
59455949
<Label>ProvisioningState</Label>
@@ -5984,6 +5988,10 @@
59845988
<Alignment>Left</Alignment>
59855989
<PropertyName>DisableOutboundSNAT</PropertyName>
59865990
</TableColumnItem>
5991+
<TableColumnItem>
5992+
<Alignment>Left</Alignment>
5993+
<PropertyName>EnableConnectionTracking</PropertyName>
5994+
</TableColumnItem>
59875995
<TableColumnItem>
59885996
<Alignment>Left</Alignment>
59895997
<PropertyName>ProvisioningState</PropertyName>

0 commit comments

Comments
 (0)