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

InterfaceMetric: Configure a static metric for an IPv4 Interface #472

Merged
merged 10 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- IPAddress
- Improved integration test structure.

### Added

- NetIPInterface
- Added `InterfaceMetric` parameter- fixes [Issue #473](https://github.com/PowerShell/xNetworking/issues/473).

### Fixed

- NetIPInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
@{
ParameterName = 'NlMtuBytes'
PropertyName = 'NlMtu'
},
@{
ParameterName = 'InterfaceMetric'
PropertyName = 'InterfaceMetric'
}
)
}
18 changes: 16 additions & 2 deletions source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ function Get-TargetResource

.PARAMETER NlMtu
Specifies the network layer Maximum Transmission Unit (MTU) value, in bytes, for an IP interface.

.PARAMETER InterfaceMetric
Specifies the metric for an IP interface.
#>
function Set-TargetResource
{
Expand Down Expand Up @@ -211,7 +214,11 @@ function Set-TargetResource

[Parameter()]
[System.UInt32]
$NlMtu
$NlMtu,

[Parameter()]
[System.UInt32]
$InterfaceMetric
)

Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): "
Expand Down Expand Up @@ -322,6 +329,9 @@ function Set-TargetResource

.PARAMETER NlMtu
Specifies the network layer Maximum Transmission Unit (MTU) value, in bytes, for an IP interface.

.PARAMETER InterfaceMetric
Specifies the metric for an IP interface.
#>
function Test-TargetResource
{
Expand Down Expand Up @@ -416,7 +426,11 @@ function Test-TargetResource

[Parameter()]
[System.UInt32]
$NlMtu
$NlMtu,

[Parameter()]
[System.UInt32]
$InterfaceMetric
)

Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ class DSC_NetIPInterface : OMI_BaseResource
[Write, Description("Specifies the receive value for a weak host model."), ValueMap{"Enabled", "Disabled"},Values{"Enabled", "Disabled"}] String WeakHostReceive;
[Write, Description("Specifies the send value for a weak host model."), ValueMap{"Enabled", "Disabled"},Values{"Enabled", "Disabled"}] String WeakHostSend;
[Write, Description("Specifies the network layer Maximum Transmission Unit (MTU) value, in bytes, for an IP interface.")] UInt32 NlMtu;
[Write, Description("Specifies the metric for an IP interface.")] UInt32 InterfaceMetric;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<#PSScriptInfo
.VERSION 1.0.0
.GUID c67b7df4-bafa-4bca-bb43-349b44df3530
.AUTHOR DSC Community
.COMPANYNAME DSC Community
.COPYRIGHT Copyright the DSC Community contributors. All rights reserved.
.TAGS DSCConfiguration
.LICENSEURI https://github.com/dsccommunity/NetworkingDsc/blob/master/LICENSE
.PROJECTURI https://github.com/dsccommunity/NetworkingDsc
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES First version.
.PRIVATEDATA 2016-Datacenter,2016-Datacenter-Server-Core
#>

#Requires -module NetworkingDsc

<#
.DESCRIPTION
Set a specified interface metrics for the network adapters with alias 'Ethernet' and 'Ethernet 2'.
#>
Configuration NetIPInterface_SetInterfaceMetric
{
Import-DscResource -Module NetworkingDsc

Node localhost
{
NetIPInterface EthernetMetric
{
InterfaceAlias = 'Ethernet'
AddressFamily = 'IPv4'
AutomaticMetric = 'Disabled'
InterfaceMetric = 10
}

NetIPInterface Ethernet2Metric
{
InterfaceAlias = 'Ethernet 2'
AddressFamily = 'IPv4'
AutomaticMetric = 'Disabled'
InterfaceMetric = 20
}
}
}
4 changes: 4 additions & 0 deletions tests/Integration/DSC_NetIPInterface.Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ try
InterfaceAlias = 'NetworkingDscLBA'
AddressFamily = 'IPv4'
AdvertiseDefaultRoute = 'Disabled'
AutomaticMetric = 'Disabled'
Dhcp = 'Disabled'
DirectedMacWolPattern = 'Disabled'
EcnMarking = 'Disabled'
Expand All @@ -148,6 +149,7 @@ try
WeakHostReceive = 'Disabled'
WeakHostSend = 'Disabled'
NlMtu = 1500
InterfaceMetric = 20
}
)
}
Expand Down Expand Up @@ -179,6 +181,7 @@ try
$current.InterfaceAlias | Should -Be $script:configData.AllNodes[0].InterfaceAlias
$current.AddressFamily | Should -Be $script:configData.AllNodes[0].AddressFamily
$current.AdvertiseDefaultRoute | Should -Be $script:configData.AllNodes[0].AdvertiseDefaultRoute
$current.AutomaticMetric | Should -Be $script:configData.AllNodes[0].AutomaticMetric
$current.Dhcp | Should -Be $script:configData.AllNodes[0].Dhcp
$current.DirectedMacWolPattern | Should -Be $script:configData.AllNodes[0].DirectedMacWolPattern
$current.EcnMarking | Should -Be $script:configData.AllNodes[0].EcnMarking
Expand All @@ -191,6 +194,7 @@ try
$current.WeakHostReceive | Should -Be $script:configData.AllNodes[0].WeakHostReceive
$current.WeakHostSend | Should -Be $script:configData.AllNodes[0].WeakHostSend
$current.NlMtu | Should -Be $script:configData.AllNodes[0].NlMtu
$current.InterfaceMetric | Should -Be $script:configData.AllNodes[0].InterfaceMetric
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Integration/DSC_NetIPInterface.config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ configuration DSC_NetIPInterface_Config_Enabled {
WeakHostReceive = $Node.WeakHostReceive
WeakHostSend = $Node.WeakHostSend
NlMtu = $Node.NlMtu
InterfaceMetric = $Node.InterfaceMetric
}
}
}
Expand All @@ -46,6 +47,7 @@ configuration DSC_NetIPInterface_Config_Disabled {
WeakHostReceive = $Node.WeakHostReceive
WeakHostSend = $Node.WeakHostSend
NlMtu = $Node.NlMtu
InterfaceMetric = $Node.InterfaceMetric
}
}
}
8 changes: 8 additions & 0 deletions tests/Unit/DSC_NetIPInterface.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ try
ParameterFilter = {
$InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $NlMtuBytes -eq 1500
}
},
@{
Name = 'InterfaceMetric'
MockedValue = [System.Uint32] 20
TestValue = [System.Uint32] 15
ParameterFilter = {
$InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $InterfaceMetric -eq 15
}
}
)

Expand Down