Technical Tip: SD-WAN Best Quality Rules - link-cost-threshold attribute
Description
This article discusses ‘link-cost-threshold’, an attribute available when using SD-WAN Best Quality Rules.
Scope
FortiGate, SD-WAN
Solution
As a primer, FortiGate SD-WAN allows administrators to define Rules that can be used to select which outgoing interface(s) should be used when forwarding user traffic. There are four modes available for these SD-WAN Rules
- Manual (default)
- Best Quality
- Lowest Cost (SLA)
- Maximize Bandwidth (SLA)
- Note that Maximize Bandwidth has been removed as a dedicated mode as of FortiOS 7.4.1 and later. Instead, Manual and Lowest Cost (SLA) rules may optionally enable load-balancing functionality (see: FortiOS 7.4 New Features - Using load balancing in a manual SD-WAN rule without configuring an SLA target)

- There is the real metric, which will be displayed in the SD-WAN GUI as well as in the output of diagnose sys sdwan service <id> in the CLI. In the above example, this would be 100ms for port1.
- Then, there is the adjusted metric. This metric is calculated using the following equation and will be used by SDWAN as the metric for the preferred interface instead of the real metric:
A = R / (1 + L/100), where:
- A is the adjusted metric,
- R is the real metric
- L is the link-cost-threshold as a percent (e.g. L = 10)
- First, it is important to define certain roles, which are Highest Priority Member (HtPM), Higher Priority Member (HrPM) and Lower Priority Member (LPM). these roles are set based on the initial configured order of interfaces in an SD-WAN rule.
- The HtPM role belongs to the first interface (i.e. the most preferred) configured on the SD-WAN rule. In this case it is port1, a
- The HrPM role is any interface that is higher/more-preferred compared to another.
- For example, port2 is an HrPM relative to port3, and port3 is an HrPM relative to port4.
- The LPM role is any interface that is lower/less-preferred compared to another. Note that interfaces may have dual-roles.
- For example, port3 is an LPM relative to port2, and yet it is also an HrPM relative to port4. On the other hand, port4 is an LPM relative to both port2 and port3.
- The Highest Priority Member (HtPM, port1 in this case) will always be assessed by it's Adjusted metric, no matter where it is currently positioned in the SD-WAN rule.
- For example, if port1 had a Real metric of 100ms of latency (Adjusted metric = ~91ms), then it will always become the outgoing interface if the other interfaces have Real metrics greater than ~91ms.
- If a Lower Priority Member (LPM) wants to be moved above a Higher Priority Member (HrPM), then the LPM must beat the HrPM's Adjusted metric.
- For example, if port2's Real metric is 200ms of latency (Adjusted metric = ~180ms) then port3's latency must be lower than 180ms for it to be moved above port2 in the SD-WAN rule.
- However, if an HrPM wants to return to its original position above an LPM, it does not use the Adjusted metric; instead, the members are compared using their Real metric.
- In the same example as above, port3 (LPM) has a Real metric of 175ms of latency, and port2 has a Real metric of 200ms. The port2 interface would NOT use an Adjusted metric here, and so its Real metric must become lower than 175ms for it to beat port3 and retake its original position in the SD-WAN rule.
Note regarding the Bandwidth metric specifically:
The above calculation is relevant for latency, jitter, packet-loss, and custom profiles. When adjusting Bandwidth metrics with link-cost-threshold, a different calculation is used:
ABWD = LPM AvBW * L/100, and
AvBWD = LPM AvBW - HPM AvBW, where
- AdBWD = Adjusted Bandwidth Difference
- AvBWD = Average Bandwidth Difference
- LPM AvBW = Average Bandwidth of the Lower Priority Member
- HPM AvBW = Average Bandwidth of the Higher Priority Member
- L = link-cost-threshold
The above formula calculates the Adjusted Bandwidth Difference (AWBD, which is a percentage of the LPM's Average Bandwidth) and compares it against the Average Bandwidth Difference (which is the difference between the average bandwidth of the Higher Priority Member and Lower Priority Member). The following is the expected result for this comparison:
- If AvBWD > ABWD, then the LPM is placed above the HPM in the SD-WAN rule (i.e. LPM is more preferred because the LPM's average bandwidth exceeds the HPM's average bandwidth plus the adjusted bandwidth difference).
- If AvBWD =< ABWD, then the LPM is placed below the HPM in the SD-WAN rule (i.e. the HPM's average bandwidth + the adjusted bandwidth difference is greater than the LPM average bandwidth).
- The above will also be true if the LPM AvBW =< HPM AvBW (i.e. the LPM only takes over if it has a significantly higher average bandwidth compared to the HPM).
Example using Bandwidth:
If port2 (HPM) has an average bandwidth of 500Mbps, port3 (LPM) has an average bandwidth of 300Mbps, and the link-cost-factor is 10, then:
AWBD = LPM AvBW * L/100
AWBD = 300 * 10/100
AWBD = 300 * 0.1
AWBD = 30
AvBWD = LPM AvBW - HPM AvBW
AvBWD = 300 - 500
AvBWD = -200
Per the above comparison, AvBWD =< ABWD (-200 < 30), so port3 (LPM) remains below port2 in the SD-WAN rule list.
Service(1): Address Mode(IPV4) flags=0x0
TOS(0x0/0x0), Protocol(0: 1->65535), Mode(auto), link-cost-factor(latency), link-cost-threshold(10), health-check(ping)
Members:
1: Seq_num(2), alive, latency: 0.011
2: Seq_num(1), alive, latency: 0.018, selected
Dst address: 10.100.21.0-10.100.21.255
