Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New packet capture Cmdlet for Network Module: VpnConnection and VpnGateway Resource #12809

Merged
merged 2 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Network/Network.Test/ScenarioTests/CortexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,21 @@ public void TestVHubRouteTableCRUD()
{
TestRunner.RunTestScript("Test-VHubRouteTableCRUD");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.brooklynft)]
public void TestVpnGatewayPacketCapture()
{
TestRunner.RunTestScript("Test-VpnGatewayPacketCapture");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.brooklynft)]
public void TestVpnConnectionPacketCapture()
{
TestRunner.RunTestScript("Test-VpnConnectionPacketCapture");
}
}
}
235 changes: 235 additions & 0 deletions src/Network/Network.Test/ScenarioTests/CortexTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,241 @@ function Test-CortexExpressRouteCRUD
}
}

<#
.SYNOPSIS
create a vpn gateway and start packet capture
#>
function Test-VpnGatewayPacketCapture
{
# Setup
$rgName = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement "West Central US"
$virtualWanName = Get-ResourceName
$virtualHubName = Get-ResourceName
$vpnGatewayName = Get-ResourceName

try
{
# Create the resource group
$resourceGroup = New-AzResourceGroup -Name $rgName -Location $rglocation

# Create the Virtual Wan
$createdVirtualWan = New-AzVirtualWan -ResourceGroupName $rgName -Name $virtualWanName -Location $rglocation -AllowVnetToVnetTraffic -AllowBranchToBranchTraffic
$virtualWan = Get-AzVirtualWan -ResourceGroupName $rgName -Name $virtualWanName
Assert-AreEqual $rgName $virtualWan.ResourceGroupName
Assert-AreEqual $virtualWanName $virtualWan.Name
Assert-AreEqual $true $virtualWan.AllowVnetToVnetTraffic
Assert-AreEqual $true $virtualWan.AllowBranchToBranchTraffic

# Create the Virtual Hub
$createdVirtualHub = New-AzVirtualHub -ResourceGroupName $rgName -Name $virtualHubName -Location $rglocation -AddressPrefix "10.0.0.0/16" -VirtualWan $virtualWan
$virtualHub = Get-AzVirtualHub -ResourceGroupName $rgName -Name $virtualHubName
Assert-AreEqual $rgName $virtualHub.ResourceGroupName
Assert-AreEqual $virtualHubName $virtualHub.Name
Assert-AreEqual "10.0.0.0/16" $virtualHub.AddressPrefix

# Create the VpnGateway
$createdVpnGateway = New-AzVpnGateway -ResourceGroupName $rgName -Name $vpnGatewayName -VirtualHub $virtualHub -VpnGatewayScaleUnit 3
Assert-AreEqual $rgName $createdVpnGateway.ResourceGroupName
Assert-AreEqual $vpnGatewayName $createdVpnGateway.Name
Assert-AreEqual 3 $createdVpnGateway.VpnGatewayScaleUnit

#create SAS URL
if ((Get-NetworkTestMode) -ne 'Playback')
{
$storetype = 'Standard_GRS'
$containerName = "testcontainer"
$storeName = 'sto' + $rgname;
New-AzStorageAccount -ResourceGroupName $rgname -Name $storeName -Location $rglocation -Type $storetype
$key = Get-AzStorageAccountKey -ResourceGroupName $rgname -Name $storeName
$context = New-AzStorageContext -StorageAccountName $storeName -StorageAccountKey $key[0].Value
New-AzStorageContainer -Name $containerName -Context $context
$container = Get-AzStorageContainer -Name $containerName -Context $context
$now=get-date
$sasurl = New-AzStorageContainerSASToken -Name $containerName -Context $context -Permission "rwd" -StartTime $now.AddHours(-1) -ExpiryTime $now.AddDays(1) -FullUri
}
else
{
$sasurl = "https://storage/test123?sp=racwdl&stvigopKcy"
}

#StartPacketCapture on gateway with Name parameter
$output = Start-AzVpnGatewayPacketCapture -ResourceGroupName $rgname -Name $vpnGatewayName
Assert-AreEqual $createdVpnGateway.ResourceGroupName $output.ResourceGroupName
Assert-AreEqual $createdVpnGateway.Name $output.Name
Assert-AreEqual $createdVpnGateway.ResourceGroupName $output.ResourceGroupName
Assert-AreEqual $createdVpnGateway.Location $output.Location
Assert-AreEqual $output.Code "Succeeded"

#StopPacketCapture on gateway with Name parameter
$output = Stop-AzVpnGatewayPacketCapture -ResourceGroupName $rgname -Name $vpnGatewayName -SasUrl $sasurl
Assert-AreEqual $createdVpnGateway.ResourceGroupName $output.ResourceGroupName
Assert-AreEqual $createdVpnGateway.Name $output.Name
Assert-AreEqual $createdVpnGateway.ResourceGroupName $output.ResourceGroupName
Assert-AreEqual $createdVpnGateway.Location $output.Location
Assert-AreEqual $output.Code "Succeeded"

#StartPacketCapture on gateway object
$a="{`"TracingFlags`":11,`"MaxPacketBufferSize`":120,`"MaxFileSize`":500,`"Filters`":[{`"SourceSubnets`":[`"10.19.0.4/32`",`"10.20.0.4/32`"],`"DestinationSubnets`":[`"10.20.0.4/32`",`"10.19.0.4/32`"],`"IpSubnetValueAsAny`":true,`"TcpFlags`":-1,`"PortValueAsAny`":true,`"CaptureSingleDirectionTrafficOnly`":true}]}"
$output = Start-AzVpnGatewayPacketCapture -InputObject $createdVpnGateway -FilterData $a
Assert-AreEqual $createdVpnGateway.ResourceGroupName $output.ResourceGroupName
Assert-AreEqual $createdVpnGateway.Name $output.Name
Assert-AreEqual $createdVpnGateway.ResourceGroupName $output.ResourceGroupName
Assert-AreEqual $createdVpnGateway.Location $output.Location
Assert-AreEqual $output.Code "Succeeded"

#StopPacketCapture on gateway object
$output = Stop-AzVpnGatewayPacketCapture -InputObject $createdVpnGateway -SasUrl $sasurl
Assert-AreEqual $createdVpnGateway.ResourceGroupName $output.ResourceGroupName
Assert-AreEqual $createdVpnGateway.Name $output.Name
Assert-AreEqual $createdVpnGateway.ResourceGroupName $output.ResourceGroupName
Assert-AreEqual $createdVpnGateway.Location $output.Location
Assert-AreEqual $output.Code "Succeeded"

# Delete the resources
$delete = Remove-AzVpnGateway -ResourceGroupName $rgName -Name $vpnGatewayName -Force -PassThru
Assert-AreEqual $True $delete

$delete = Remove-AzVirtualHub -ResourceGroupName $rgName -Name $virtualHubName -Force -PassThru
Assert-AreEqual $True $delete

$delete = Remove-AzVirtualWan -ResourceGroupName $rgName -Name $virtualWanName -Force -PassThru
Assert-AreEqual $True $delete
}
finally
{
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
CortexCRUD
#>
function Test-VpnConnectionPacketCapture
{
# Setup
$rgName = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement "East US"

$virtualWanName = Get-ResourceName
$virtualHubName = Get-ResourceName
$vpnSiteName = Get-ResourceName
$vpnGatewayName = Get-ResourceName
$remoteVirtualNetworkName = Get-ResourceName
$vpnConnectionName = Get-ResourceName
$hubVnetConnectionName = Get-ResourceName
$vpnSiteLink1Name = Get-ResourceName
$vpnSiteLink2Name = Get-ResourceName
$vpnLink1ConnectionName = Get-ResourceName
$vpnLink2ConnectionName = Get-ResourceName
$storeName = 'blob' + $rgName

try
{
# Create the resource group
$resourceGroup = New-AzResourceGroup -Name $rgName -Location $rglocation

# Create the Virtual Wan
$createdVirtualWan = New-AzVirtualWan -ResourceGroupName $rgName -Name $virtualWanName -Location $rglocation -AllowVnetToVnetTraffic -AllowBranchToBranchTraffic
$virtualWan = Get-AzVirtualWan -ResourceGroupName $rgName -Name $virtualWanName
Assert-AreEqual $rgName $virtualWan.ResourceGroupName
Assert-AreEqual $virtualWanName $virtualWan.Name

# Create the Virtual Hub
$createdVirtualHub = New-AzVirtualHub -ResourceGroupName $rgName -Name $virtualHubName -Location $rglocation -AddressPrefix "192.168.1.0/24" -VirtualWan $virtualWan
$virtualHub = Get-AzVirtualHub -ResourceGroupName $rgName -Name $virtualHubName
Assert-AreEqual $rgName $virtualHub.ResourceGroupName
Assert-AreEqual $virtualHubName $virtualHub.Name
Assert-AreEqual "192.168.1.0/24" $virtualHub.AddressPrefix

# Create the VpnSite with Links
$vpnSiteAddressSpaces = New-Object string[] 2
$vpnSiteAddressSpaces[0] = "192.169.2.0/24"
$vpnSiteAddressSpaces[1] = "192.169.3.0/24"
$vpnSiteLink1 = New-AzVpnSiteLink -Name $vpnSiteLink1Name -IpAddress "5.5.5.5" -LinkProviderName "SomeTelecomProvider1" -LinkSpeedInMbps "10"
$vpnSiteLink2 = New-AzVpnSiteLink -Name $vpnSiteLink2Name -IpAddress "5.5.5.6" -LinkProviderName "SomeTelecomProvider2" -LinkSpeedInMbps "10"

$createdVpnSite = New-AzVpnSite -ResourceGroupName $rgName -Name $vpnSiteName -Location $rglocation -VirtualWan $virtualWan -AddressSpace $vpnSiteAddressSpaces -DeviceModel "SomeDevice" -DeviceVendor "SomeDeviceVendor" -VpnSiteLink @($vpnSiteLink1, $vpnSiteLink2)
Assert-AreEqual $rgName $createdVpnSite.ResourceGroupName
Assert-AreEqual $vpnSiteName $createdVpnSite.Name
Assert-AreEqual 2 $createdVpnSite.VpnSiteLinks.Count

# Create the VpnGateway
$createdVpnGateway = New-AzVpnGateway -ResourceGroupName $rgName -Name $vpnGatewayName -VirtualHub $virtualHub -VpnGatewayScaleUnit 3
Assert-AreEqual $rgName $createdVpnGateway.ResourceGroupName
Assert-AreEqual $vpnGatewayName $createdVpnGateway.Name
Assert-AreEqual 3 $createdVpnGateway.VpnGatewayScaleUnit


# Create the VpnConnection with site with links
$vpnSiteLinkConnection1 = New-AzVpnSiteLinkConnection -Name $vpnLink1ConnectionName -VpnSiteLink $createdVpnSite.VpnSiteLinks[0] -ConnectionBandwidth 100
$vpnSiteLinkConnection2 = New-AzVpnSiteLinkConnection -Name $vpnLink2ConnectionName -VpnSiteLink $createdVpnSite.VpnSiteLinks[1] -ConnectionBandwidth 10

$createdVpnConnection = New-AzVpnConnection -ResourceGroupName $rgName -ParentResourceName $vpnGatewayName -Name $vpnConnectionName -VpnSite $createdVpnSite -VpnSiteLinkConnection @($vpnSiteLinkConnection1, $vpnSiteLinkConnection2)

#create SAS URL
if ((Get-NetworkTestMode) -ne 'Playback')
{
$storetype = 'Standard_GRS'
$containerName = "testcontainer"
$storeName = 'sto2' + $rgname;
New-AzStorageAccount -ResourceGroupName $rgname -Name $storeName -Location $rglocation -Type $storetype
$key = Get-AzStorageAccountKey -ResourceGroupName $rgname -Name $storeName
$context = New-AzStorageContext -StorageAccountName $storeName -StorageAccountKey $key[0].Value
New-AzStorageContainer -Name $containerName -Context $context
$container = Get-AzStorageContainer -Name $containerName -Context $context
$now=get-date
$sasurl = New-AzStorageContainerSASToken -Name $containerName -Context $context -Permission "rwd" -StartTime $now.AddHours(-1) -ExpiryTime $now.AddDays(1) -FullUri
}
else
{
$sasurl = "https://storage/test123?sp=racwdl&stvigopKcy"
}

$SiteLinkConnections = $vpnSiteLinkConnection1.Name + "," + $vpnSiteLinkConnection2.Name
# StartPacketCapture on VpnConnection with Name parameter
$output = Start-AzVpnConnectionPacketCapture -ResourceGroupName $rgname -Name $vpnConnectionName -ParentResourceName $vpnGatewayName -LinkConnectionName $SiteLinkConnections
Assert-AreEqual $createdVpnConnection.Name $output.Name
Assert-AreEqual $output.Code "Succeeded"

#StopPacketCapture on VpnConnection with Name parameter
$output = Stop-AzVpnConnectionPacketCapture -ResourceGroupName $rgname -Name $vpnConnectionName -ParentResourceName $vpnGatewayName -SasUrl $sasurl -LinkConnectionName $SiteLinkConnections
Assert-AreEqual $createdVpnConnection.Name $output.Name
Assert-AreEqual $output.Code "Succeeded"

#StartPacketCapture on gateway object with filterData
$a="{`"TracingFlags`":11,`"MaxPacketBufferSize`":120,`"MaxFileSize`":500,`"Filters`":[{`"SourceSubnets`":[`"10.19.0.4/32`",`"10.20.0.4/32`"],`"DestinationSubnets`":[`"10.20.0.4/32`",`"10.19.0.4/32`"],`"IpSubnetValueAsAny`":true,`"TcpFlags`":-1,`"PortValueAsAny`":true,`"CaptureSingleDirectionTrafficOnly`":true}]}"
$output = Start-AzVpnConnectionPacketCapture -InputObject $createdVpnConnection -FilterData $a -LinkConnectionName $SiteLinkConnections
Assert-AreEqual $createdVpnConnection.Name $output.Name
Assert-AreEqual $output.Code "Succeeded"

#StopPacketCapture on gateway object
$output = Stop-AzVpnConnectionPacketCapture -InputObject $createdVpnConnection -SasUrl $sasurl -LinkConnectionName $SiteLinkConnections
Assert-AreEqual $createdVpnConnection.Name $output.Name
Assert-AreEqual $output.Code "Succeeded"

$delete = Remove-AzVpnConnection -ResourceGroupName $rgName -ParentResourceName $vpnGatewayName -Name $vpnConnectionName -Force -PassThru
Assert-AreEqual $True $delete

$delete = Remove-AzVpnGateway -ResourceGroupName $rgName -Name $vpnGatewayName -Force -PassThru
Assert-AreEqual $True $delete

$delete = Remove-AzVpnSite -ResourceGroupName $rgName -Name $vpnSiteName -Force -PassThru
Assert-AreEqual $True $delete

$delete = Remove-AzVirtualHub -ResourceGroupName $rgName -Name $virtualHubName -Force -PassThru
Assert-AreEqual $True $delete

$delete = Remove-AzVirtualWan -ResourceGroupName $rgName -Name $virtualWanName -Force -PassThru
Assert-AreEqual $True $delete
}
finally
{
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Disconnect site to site vpn gateway BgpSettings
Expand Down
Loading