Search code examples
windowsnetwork-programmingtcpretransmit-timeout

How does Windows decide which setting/template (Internet vs Datacenter) is applied to TCP connections?


In order to globally configure Minimum RTO; Delayed Ack Timeout; Congestion algo etc. under Windows 7 and above one is supposed to use network TCP templates. To see those you can use Get-NetTCPSetting powershell cmdlet:

PS C:\Users\Administrator> Get-NetTCPSetting

(...)

SettingName                   : Datacenter
MinRto(ms)                    : 20
InitialCongestionWindow(MSS)  : 4
CongestionProvider            : DCTCP
CwndRestart                   : True
DelayedAckTimeout(ms)         : 10
MemoryPressureProtection      : Enabled
AutoTuningLevelLocal          : Normal
AutoTuningLevelGroupPolicy    : NotConfigured
AutoTuningLevelEffective      : Local
EcnCapability                 : Enabled
Timestamps                    : Disabled
InitialRto(ms)                : 3000
ScalingHeuristics             : Disabled
DynamicPortRangeStartPort     : 49152
DynamicPortRangeNumberOfPorts : 16384

SettingName                   : Internet
MinRto(ms)                    : 300
InitialCongestionWindow(MSS)  : 4
CongestionProvider            : CTCP
CwndRestart                   : False
DelayedAckTimeout(ms)         : 50
MemoryPressureProtection      : Enabled
AutoTuningLevelLocal          : Normal
AutoTuningLevelGroupPolicy    : NotConfigured
AutoTuningLevelEffective      : Local
EcnCapability                 : Enabled
Timestamps                    : Disabled
InitialRto(ms)                : 3000
ScalingHeuristics             : Disabled
DynamicPortRangeStartPort     : 49152
DynamicPortRangeNumberOfPorts : 16384

In order to get individual connection and settings applied to them one can use Get-NetTCPConnection cmdlet:

PS C:\Users\Administrator> Get-NetTCPConnection

LocalAddress                        LocalPort RemoteAddress                       RemotePort State       AppliedSetting
------------                        --------- -------------                       ---------- -----       --------------
(...)
192.168.75.69                       63220     192.168.75.66                       1433       Established Datacenter
192.168.75.69                       63208     192.168.75.61                       445        Established Internet
192.168.101.13                      63061     185.97.X.X                          20467      Established Datacenter
192.168.101.13                      63059     209.191.X.X                         18083      Established Internet
(...)

How do I influence (or at least how is made) the choice of Internet vs Datacenter TCP settings? We have several low latency connections that we would like to treat with Datacentre settings (to speed up recovery from communication glitches), while still I do not want to blindly apply this to all connections.


Solution

  • The settings profile applied to a given connection is based on the matching Transport Filter. By default, there is a single filter that applies the Automatic settings profile to all connections, which is why yours are seemingly random.

    PS C:\> Get-NetTransportFilter
    
    SettingName       : Automatic
    Protocol          : TCP
    LocalPortStart    : 0
    LocalPortEnd      : 65535
    RemotePortStart   : 0
    RemotePortEnd     : 65535
    DestinationPrefix : *
    

    The New-NetTransportFilter cmdlet allows you to map connections to specific profiles based on either port numbers or IP address.

    You can use something like

    New-NetTransportFilter -SettingName Datacenter -DestinationPrefix 192.168.75.0/24
    

    Or

    New-NetTransportFilter -SettingName DataCenter -LocalPortStart 0 -LocalPortEnd 65536 -RemotePortStart 1433 -RemotePortEnd 1433