Skip to content

Commit 9c22f1a

Browse files
authored
Merge branch 'network-september' into PacketCaptureChanges
2 parents cf340a1 + 53da254 commit 9c22f1a

14 files changed

+17256
-9
lines changed

src/Network/Network.Test/ScenarioTests/VirtualNetworkGatewayConnectionTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,12 @@ public void TestVirtualNetworkGatewayConnectionPacketCapture()
8989
TestRunner.RunTestScript("Test-VirtualNetworkGatewayConnectionPacketCapture");
9090
}
9191

92+
[Fact]
93+
[Trait(Category.AcceptanceType, Category.CheckIn)]
94+
[Trait(Category.Owner, NrpTeamAlias.brooklynft_subset1)]
95+
public void TestVirtualNetworkGatewayConnectionWithTrafficSelectorCRUD()
96+
{
97+
TestRunner.RunTestScript("Test-VirtualNetworkGatewayConnectionWithTrafficSelector");
98+
}
9299
}
93100
}

src/Network/Network.Test/ScenarioTests/VirtualNetworkGatewayConnectionTests.ps1

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,75 @@ function Test-VirtualNetworkGatewayConnectionWithBgpCRUD
145145
}
146146
}
147147

148+
<#
149+
.SYNOPSIS
150+
Virtual network gateway connection tests
151+
#>
152+
function Test-VirtualNetworkGatewayConnectionWithTrafficSelector
153+
{
154+
# Setup
155+
$rgname = Get-ResourceGroupName
156+
$rname = Get-ResourceName
157+
$domainNameLabel = Get-ResourceName
158+
$vnetName = Get-ResourceName
159+
$localnetName = Get-ResourceName
160+
$vnetConnectionName = Get-ResourceName
161+
$publicIpName = Get-ResourceName
162+
$vnetGatewayConfigName = Get-ResourceName
163+
$rglocation = Get-ProviderLocation ResourceManagement
164+
$resourceTypeParent = "Microsoft.Network/connections"
165+
$location = Get-ProviderLocation $resourceTypeParent
166+
167+
try
168+
{
169+
# Create the resource group
170+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
171+
172+
# Create the Virtual Network
173+
$subnet = New-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -AddressPrefix 10.0.0.0/24
174+
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
175+
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
176+
$subnet = Get-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet
177+
$trafficSelector = New-AzIpsecTrafficSelectorPolicy -LocalAddressRange ("20.20.0.0/16") -RemoteAddressRange ("10.10.0.0/16")
178+
179+
# Create the publicip
180+
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel
181+
182+
# Create VirtualNetworkGateway
183+
$vnetIpConfig = New-AzVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName -PublicIpAddress $publicip -Subnet $subnet
184+
185+
# Also test overriding the gateway ASN
186+
$actual = New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -IpConfigurations $vnetIpConfig -GatewayType Vpn -VpnType RouteBased -GatewaySku Standard -Asn 55000
187+
$vnetGateway = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
188+
Assert-AreEqual $vnetGateway.BgpSettings.Asn $actual.BgpSettings.Asn
189+
190+
# Create LocalNetworkGateway
191+
$actual = New-AzLocalNetworkGateway -ResourceGroupName $rgname -name $localnetName -location $location -AddressPrefix 192.168.0.0/16 -GatewayIpAddress 192.168.3.10
192+
$localnetGateway = Get-AzLocalNetworkGateway -ResourceGroupName $rgname -name $localnetName
193+
194+
# Create & Get VirtualNetworkGatewayConnection
195+
$actual = New-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName -location $location -VirtualNetworkGateway1 $vnetGateway -LocalNetworkGateway2 $localnetGateway -ConnectionType IPsec -RoutingWeight 3 -SharedKey abc -TrafficSelectorPolicy ($trafficSelector)
196+
$connection = Get-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName
197+
Assert-NotNull $connection;
198+
Assert-NotNull $connection.TrafficSelectorPolicies;
199+
Assert-AreEqual $connection.TrafficSelectorPolicies.Count 1
200+
201+
$connectionTrafficSelector = $connection.TrafficSelectorPolicies[0];
202+
Assert-AreEqual $trafficSelector.LocalAddressRanges[0] $connectionTrafficSelector.LocalAddressRanges[0];
203+
Assert-AreEqual $trafficSelector.RemoteAddressRanges[0] $connectionTrafficSelector.RemoteAddressRanges[0];
204+
205+
# Delete VirtualNetworkGatewayConnection
206+
$delete = Remove-AzVirtualNetworkGatewayConnection -ResourceGroupName $actual.ResourceGroupName -name $vnetConnectionName -PassThru -Force
207+
Assert-AreEqual true $delete
208+
209+
}
210+
finally
211+
{
212+
# Cleanup
213+
Clean-ResourceGroup $rgname
214+
}
215+
}
216+
148217
<#
149218
.SYNOPSIS
150219
Virtual network gateway connection tests with Ipsec Policies and policy-based TS

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.VirtualNetworkGatewayConnectionTests/TestVirtualNetworkGatewayConnectionWithTrafficSelectorCRUD.json

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

src/Network/Network/Az.Network.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
290290
'Remove-AzVirtualNetworkGatewayConnection',
291291
'Reset-AzVirtualNetworkGatewayConnectionSharedKey',
292292
'Set-AzVirtualNetworkGatewayConnectionSharedKey',
293-
'Set-AzVirtualNetworkGatewayConnection', 'New-AzIpsecPolicy',
293+
'Set-AzVirtualNetworkGatewayConnection', 'New-AzIpsecPolicy', "New-AzIpsecTrafficSelectorPolicy",
294294
'Get-AzLoadBalancerBackendAddressPoolConfig',
295295
'Add-AzLoadBalancerBackendAddressPoolConfig',
296296
'New-AzLoadBalancerBackendAddressPoolConfig',

src/Network/Network/ChangeLog.md

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

2121
## Upcoming Release
22+
* Added support for the adding traffic selectors to Virtual Network Gateway Connections
23+
- New cmdlets added:
24+
- New-AzureRmTrafficSelectorPolicy
25+
- Cmdlets updated with optional parameter -TrafficSelectorPolicies
26+
-New-AzureRmVirtualNetworkGatewayConnection
27+
-Set-AzureRmVirtualNetworkGatewayConnection
2228
* Add support for ESP and AH protocols in network security rule configurations
2329
- Updated cmdlets:
2430
- Add-AzNetworkSecurityRuleConfig
@@ -236,3 +242,4 @@
236242
- Set-AzApplicationGatewaySslCertificate
237243
- New-AzApplicationGateway cmdlet updated with optional parameter -UserAssignedIdentityId, -UserAssignedIdentity
238244
* Add MaxCapacity property in ApplicationGatewayAutoscaleConfiguration
245+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
16+
using Microsoft.WindowsAzure.Commands.Common.Attributes;
17+
18+
namespace Microsoft.Azure.Commands.Network.Models
19+
{
20+
public class PSTrafficSelectorPolicy
21+
{
22+
/// <summary>
23+
/// CIDR formatted local address spaces
24+
/// </summary>
25+
[Ps1Xml(Target = ViewControl.Table)]
26+
public string[] LocalAddressRanges { get; set; }
27+
28+
/// <summary>
29+
/// CIDR formatted remote address spaces
30+
/// </summary>
31+
[Ps1Xml(Target = ViewControl.Table)]
32+
public string[] RemoteAddressRanges { get; set; }
33+
}
34+
}

src/Network/Network/Models/PSVirtualNetworkGatewayConnection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public class PSVirtualNetworkGatewayConnection : PSTopLevelResource
5959

6060
public List<PSIpsecPolicy> IpsecPolicies { get; set; }
6161

62+
public List<PSTrafficSelectorPolicy> TrafficSelectorPolicies { get; set; }
63+
6264
public bool ExpressRouteGatewayBypass { get; set; }
6365

6466
[Ps1Xml(Target = ViewControl.Table)]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Network.Models;
16+
using System;
17+
using System.Management.Automation;
18+
using System.Management.Automation.Internal;
19+
using MNM = Microsoft.Azure.Management.Network.Models;
20+
21+
namespace Microsoft.Azure.Commands.Network
22+
{
23+
[Cmdlet(
24+
"New",
25+
ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "IpsecTrafficSelectorPolicy",
26+
DefaultParameterSetName = "ByName", SupportsShouldProcess = true),
27+
OutputType(typeof(PSTrafficSelectorPolicy))]
28+
public class NewAzureRmTrafficSelectorPolicyCommand : NetworkBaseCmdlet
29+
{
30+
[Parameter(
31+
Mandatory = true,
32+
ValueFromPipelineByPropertyName = true,
33+
HelpMessage = "A collection of CIDR address ranges")]
34+
[ValidateNotNullOrEmpty]
35+
public virtual string[] LocalAddressRange { get; set; }
36+
37+
[Parameter(
38+
Mandatory = true,
39+
ValueFromPipelineByPropertyName = true,
40+
HelpMessage = "A collection of CIDR address ranges")]
41+
[ValidateNotNullOrEmpty]
42+
public virtual string[] RemoteAddressRange { get; set; }
43+
44+
public override void Execute()
45+
{
46+
base.Execute();
47+
var trafficSelectorPolicy = new PSTrafficSelectorPolicy();
48+
trafficSelectorPolicy.LocalAddressRanges = this.LocalAddressRange;
49+
trafficSelectorPolicy.RemoteAddressRanges = this.RemoteAddressRange;
50+
51+
WriteObject(trafficSelectorPolicy);
52+
}
53+
}
54+
}

src/Network/Network/VirtualNetworkGatewayConnection/NewAzureVirtualNetworkGatewayConnectionCommand.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ public class NewAzureVirtualNetworkGatewayConnectionCommand : VirtualNetworkGate
144144
HelpMessage = "A list of IPSec policies.")]
145145
public PSIpsecPolicy[] IpsecPolicies { get; set; }
146146

147+
[Parameter(
148+
Mandatory = false,
149+
ValueFromPipelineByPropertyName = true,
150+
HelpMessage = "A list of traffic selector policies.")]
151+
public PSTrafficSelectorPolicy[] TrafficSelectorPolicy { get; set; }
152+
147153
[Parameter(
148154
Mandatory = false,
149155
HelpMessage = "Gateway connection protocol:IKEv1/IKEv2")]
@@ -218,12 +224,17 @@ private PSVirtualNetworkGatewayConnection CreateVirtualNetworkGatewayConnection(
218224
vnetGatewayConnection.Peer = new PSResourceId();
219225
vnetGatewayConnection.Peer.Id = this.PeerId;
220226
}
221-
227+
222228
if (this.IpsecPolicies != null)
223229
{
224230
vnetGatewayConnection.IpsecPolicies = this.IpsecPolicies?.ToList();
225231
}
226232

233+
if (this.TrafficSelectorPolicy != null)
234+
{
235+
vnetGatewayConnection.TrafficSelectorPolicies = this.TrafficSelectorPolicy?.ToList();
236+
}
237+
227238
// Map to the sdk object
228239
var vnetGatewayConnectionModel = NetworkResourceManagerProfile.Mapper.Map<MNM.VirtualNetworkGatewayConnection>(vnetGatewayConnection);
229240
vnetGatewayConnectionModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);

src/Network/Network/VirtualNetworkGatewayConnection/UpdateAzureVirtualNetworkGatewayConnectionCommand.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ public class SetAzureVirtualNetworkGatewayConnectionCommand : VirtualNetworkGate
5353
HelpMessage = "A list of IPSec policies.")]
5454
public PSIpsecPolicy[] IpsecPolicies { get; set; }
5555

56+
[Parameter(
57+
Mandatory = false,
58+
ValueFromPipelineByPropertyName = true,
59+
HelpMessage = "A list of traffic selector policies.")]
60+
public PSTrafficSelectorPolicy[] TrafficSelectorPolicy { get; set; }
61+
5662
[Parameter(
5763
Mandatory = true,
5864
ParameterSetName = VirtualNetworkGatewayParameterSets.UpdateResourceWithTags,
@@ -98,6 +104,11 @@ public override void Execute()
98104
this.VirtualNetworkGatewayConnection.IpsecPolicies = this.IpsecPolicies?.ToList();
99105
}
100106

107+
if (this.TrafficSelectorPolicy != null)
108+
{
109+
this.VirtualNetworkGatewayConnection.TrafficSelectorPolicies = this.TrafficSelectorPolicy?.ToList();
110+
}
111+
101112
var vnetGatewayConnectionModel = NetworkResourceManagerProfile.Mapper.Map<MNM.VirtualNetworkGatewayConnection>(this.VirtualNetworkGatewayConnection);
102113

103114
vnetGatewayConnectionModel.Tags =

src/Network/Network/help/Az.Network.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,9 @@ Creates a Azure Firewall Network Collection of Network rules.
680680
### [New-AzIpsecPolicy](New-AzIpsecPolicy.md)
681681
Creates an IPSec Policy.
682682

683+
### [New-AzIpsecTrafficSelectorPolicy](New-AzIpsecTrafficSelectorPolicy.md)
684+
Creates an IPSec Traffic Selector Policy.
685+
683686
### [New-AzLoadBalancer](New-AzLoadBalancer.md)
684687
Creates a load balancer.
685688

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
external help file: Microsoft.Azure.PowerShell.Cmdlets.Network.dll-Help.xml
3+
Module Name: Az.Network
4+
online version: https://docs.microsoft.com/en-us/powershell/module/az.network/new-azipsectrafficselectorpolicy
5+
schema: 2.0.0
6+
---
7+
8+
# New-AzIpsecTrafficSelectorPolicy
9+
10+
## SYNOPSIS
11+
Creates a traffic selector policy.
12+
13+
## SYNTAX
14+
15+
```
16+
New-AzIpsecTrafficSelectorPolicy -LocalAddressRange <String[]> -RemoteAddressRange <String[]>
17+
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
18+
```
19+
20+
## DESCRIPTION
21+
The New-AzTrafficSelectorPolicy cmdlet creates a traffic selector policy proposal to be used in a virtual network gateway connection.
22+
23+
## EXAMPLES
24+
25+
### Example 1
26+
```powershell
27+
$trafficSelectorPolicy = New-AzIpsecTrafficSelectorPolicy -LocalAddressRange ("10.10.10.0/24", "20.20.20.0/24") -RemoteAddressRange ("30.30.30.0/24", "40.40.40.0/24")
28+
New-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName -location $location -VirtualNetworkGateway1 $vnetGateway -LocalNetworkGateway2 $localnetGateway -ConnectionType IPsec -RoutingWeight 3 -SharedKey $sharedKey -UsePolicyBasedTrafficSelectors $true -TrafficSelectorPolicies ($trafficSelectorPolicy)
29+
```
30+
31+
Creates an instance of a traffic selector policy and adds it as a parameter when creating a virtual network gateway connection with an IKEv2 protocol.
32+
33+
## PARAMETERS
34+
35+
### -DefaultProfile
36+
The credentials, account, tenant, and subscription used for communication with Azure.
37+
38+
```yaml
39+
Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
40+
Parameter Sets: (All)
41+
Aliases: AzContext, AzureRmContext, AzureCredential
42+
43+
Required: False
44+
Position: Named
45+
Default value: None
46+
Accept pipeline input: False
47+
Accept wildcard characters: False
48+
```
49+
50+
### -LocalAddressRange
51+
A collection of CIDR address ranges
52+
53+
```yaml
54+
Type: System.String[]
55+
Parameter Sets: (All)
56+
Aliases:
57+
58+
Required: True
59+
Position: Named
60+
Default value: None
61+
Accept pipeline input: True (ByPropertyName)
62+
Accept wildcard characters: False
63+
```
64+
65+
### -RemoteAddressRange
66+
A collection of CIDR address ranges
67+
68+
```yaml
69+
Type: System.String[]
70+
Parameter Sets: (All)
71+
Aliases:
72+
73+
Required: True
74+
Position: Named
75+
Default value: None
76+
Accept pipeline input: True (ByPropertyName)
77+
Accept wildcard characters: False
78+
```
79+
80+
### CommonParameters
81+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
82+
83+
## INPUTS
84+
85+
### System.String[]
86+
87+
## OUTPUTS
88+
89+
### Microsoft.Azure.Commands.Network.Models.PSTrafficSelectorPolicy
90+
91+
## NOTES
92+
93+
## RELATED LINKS

0 commit comments

Comments
 (0)