Lab 04-04 · ECMP: two equal paths at once (optional)¶
MTCNA
Module 4 · Routing of the MikroTik MTCNA course, official slides p179–180 (ECMP, Equal Cost Multi-Path, and the optional LAB "Añadir rutas ECMP a Lab anterior") and p165 (check-gateway in ECMP routes).
At the supermarket there are two checkouts open, both with short queues. The staff do not send everybody to checkout 1 until it is full: customers spread over both. And if checkout 2 suddenly closes, nobody stays stuck in front of it; everybody walks over to checkout 1.
At the end of Lab 04-03 your router reached neighbour A's network through B (the detour). In Lab 04-02 it reached it directly. Both paths work, both are one route with distance 1. Why choose? In this lab you give your router both routes at the same time. It will spread the traffic over the two paths, and when one of them dies it will notice and use only the other: ECMP with check-gateway.
What you will learn
- Explain ECMP (Equal Cost Multi-Path): several equally good routes to the same destination, used together.
- Create ECMP in RouterOS v7 (one route per gateway) and spot the v6 syntax on the slides that v7 rejects.
- Read the
+flag and explain how RouterOS chooses a path per source and destination address (the hash). - Prove the load sharing with
traceroutefrom several source addresses. - Add check-gateway=ping and prove the failover: switch a router off and watch the traffic move.
The analogy: two open checkouts¶
| Supermarket | Network | What it means |
|---|---|---|
| Two checkouts, equal queues | Two routes to 192.168.89.0/24, same distance |
ECMP |
| A customer always uses the same till | A pair of addresses always uses the same path | The hash keeps a conversation on one path |
| Different customers, different tills | Different address pairs spread over both paths | Load sharing |
| A till closes, everybody moves | A gateway stops answering, its route goes inactive | check-gateway failover |
What is ECMP?¶
ECMP (Equal Cost Multi-Path) means the router keeps several routes to the same destination with the same distance and uses all of them, spreading the traffic.
Remember Lab 04-01: when two routes are equally specific, the lower distance wins. If the distances are also
equal, RouterOS does not throw one away: both become active and are marked with the flag + (ECMP). All
the reachable next hops are copied to the FIB (Forwarding Information Base, slide p179), the fast table
the router actually uses to forward packets, built from the best routes of the routing table.
Which packet takes which path?¶
Sending packet 1 by path A, packet 2 by path B and so on would mix up the order of a conversation. So the
router chooses a path per flow: it computes a hash (a quick fingerprint number) from fields of the
packet, and the same fields always give the same path. The slides (p179) list the fields used by RouterOS v6:
source and destination address, incoming interface, routing mark and ToS. In RouterOS v7 the fields are set in
IP → Settings → IPv4 Multipath Hash Policy; the default, l3, uses the source and destination
addresses.
Consequence: pc1 talking to pc2 always uses the same path. To see both paths in use you need several different address pairs, as in a real office with many laptops. You will fake that in Step 3.
RouterOS v7 syntax differs from the slides
In RouterOS v6 an ECMP route was one route with several gateways: gateway=10.0.0.12,10.0.0.13. In
RouterOS v7 that command fails with invalid or unexpected argument. In v7 you add one route per
gateway, with the same destination and the same distance, and RouterOS groups them.
check-gateway: noticing a closed till¶
A static route does not know whether its gateway is alive. With check-gateway=ping (slide p165) the router
pings the gateway every 10 seconds; after two timeouts in a row the route becomes inactive (flag
I). In an ECMP group, only that route is excluded and the others keep working. When the gateway answers
again, the route comes back by itself.
The scenario¶
The same network as Lab 04-03, which is already solved: your router reaches A's LAN through B.
flowchart LR
PC1["<b>pc1</b><br>your laptop<br>+ 8 test addresses"]
R1["<b>r1 · you</b><br>10.0.0.11"]
R3["<b>r3 · B</b><br>10.0.0.13<br>route to A"]
R2["<b>r2 · A</b><br>10.0.0.12"]
PC2["<b>pc2</b><br>A's laptop<br>192.168.89.254"]
PC1 --> R1
R1 -->|"path 1 · via B (from Lab 04-03)"| R3
R3 --> R2
R1 -->|"path 2 · direct (new)"| R2
R2 --> PC2
| Node | Role | Address |
|---|---|---|
class-ap |
The trainer's router, joins all routers in 10.0.0.0/24 |
10.0.0.1/24 |
r1 |
Your router; has 192.168.89.0/24 → 10.0.0.13 from Lab 04-03 |
10.0.0.11 · LAN 192.168.88.1/24 |
r2 |
Neighbour A | 10.0.0.12 · LAN 192.168.89.1/24 |
r3 |
Neighbour B; has 192.168.89.0/24 → 10.0.0.12 from Lab 04-03 |
10.0.0.13 · LAN 192.168.90.1/24 |
pc1, pc2, pc3 |
Laptops of you, A and B | 192.168.88.254, 192.168.89.254, 192.168.90.254 |
Why ether2 and not ether1?
On a real hAP the Internet port is ether1. In the virtual lab ether1 is reserved for the lab itself (containerlab uses it to manage the router), so the Internet port is ether2 and the LAN ports start at ether3. Never touch ether1 in these labs. In the classroom your hAP's ether1 is plugged by cable into the trainer's router, exactly like ether2 here.
Start the lab¶
Download the lab files and unzip them: 04-04-ecmp.zip. Open a terminal inside the 04-04-ecmp folder.
Four RouterOS routers have to boot: give it about three minutes. Then:
ssh admin@clab-mtcna-04-04-r1 # password: admin (also r2, r3)
docker exec -it clab-mtcna-04-04-pc1 bash # also pc2
At any moment you can run CLAB_EXEC="docker exec" ./check.sh. Note that the check switches r3's ether2
off for about half a minute to test the failover, and switches it back on at the end.
The laptops ask for their address by themselves when the lab starts; if ip -br address show eth1 shows
no IPv4 address yet (the router was still booting), run dhclient -v eth1.
Step 1 · Add the second path¶
Your router already has path 1 (via B). Add path 2, straight to A, with the same destination and the same distance (1, the default for static routes).
First try the v6 way from the slides, to see it fail:
RouterOS 7 answers invalid or unexpected argument. Now the v7 way. WinBox: IP → Routes → +, Dst. Address
192.168.89.0/24, Gateway 10.0.0.12, Check Gateway ping.
/ip route add dst-address=192.168.89.0/24 gateway=10.0.0.12 check-gateway=ping
/ip route print where dst-address=192.168.89.0/24
Expected:
Flags: A - ACTIVE; s - STATIC; + - ECMP
# DST-ADDRESS GATEWAY ROUTING-TABLE DISTANCE
0 As+ 192.168.89.0/24 10.0.0.13 main 1
1 As+ 192.168.89.0/24 10.0.0.12 main 1
Both routes are active and both carry the + flag. That is ECMP.
Check yourself
- What would happen if you gave the new route
distance=2? Would it still be ECMP?
Done when both routes show As+.
Step 2 · Let the old route check its gateway too¶
Path 1 was created in Lab 04-03 without check-gateway. Without it, if B dies, your router would keep sending
half the flows into a black hole. WinBox: double-click the route via 10.0.0.13, Check Gateway ping.
/ip route set [find where dst-address=192.168.89.0/24 and gateway=10.0.0.13] check-gateway=ping
/ip route print detail where dst-address=192.168.89.0/24
Expected: both routes show check-gateway=ping.
Done when both ECMP routes have check-gateway=ping.
Step 3 · See the load sharing¶
pc1 talking to pc2 always hashes to the same path. To imitate an office full of laptops, give pc1 eight extra addresses and send a traceroute from each one. On pc1:
for i in 1 2 3 4 5 6 7 8; do ip addr add 192.168.88.20$i/24 dev eth1; done
for i in 1 2 3 4 5 6 7 8; do
echo -n "from 192.168.88.20$i: "; traceroute -n -q 1 -m 2 -s 192.168.88.20$i 192.168.89.254 | tail -1
done
Expected: some sources show 10.0.0.12 as hop 2 (direct to A), others 10.0.0.13 (via B). Run the second loop
again: every source keeps its path. The split is decided by the hash, so your numbers will differ from your
classmates'.
Check yourself
- How many of your eight sources went through B, and how many straight to A?
- Why does one source always take the same path? What could go wrong if packets of one conversation were sent alternately over both paths?
Done when you see both 10.0.0.12 and 10.0.0.13 in the results.
Step 4 · Close one checkout: failover¶
Now switch neighbour B's router off the class network. On r3:
On r1, watch the routes for about half a minute (WinBox: IP → Routes, it refreshes by itself):
After two failed pings (about 20 seconds), the route via B changes:
Flags: I - INACTIVE, A - ACTIVE; s - STATIC
0 Is 192.168.89.0/24 10.0.0.13 main 1
1 As 192.168.89.0/24 10.0.0.12 main 1
The + is gone: there is only one active path left. Run the traceroute loop of Step 3 again on pc1: every
source now goes through 10.0.0.12, and pings still work.
Bring B back:
Within about 10 seconds (the next successful ping) the route via B is active again and the + flags return.
Check yourself
- How long did your router take to mark the route via B inactive? Compare with the rule on slide p165.
- Without check-gateway, what would have happened to the flows that hashed onto B?
Done when you have seen the route via B go I and come back A. Then remove the test addresses
(for i in 1 2 3 4 5 6 7 8; do ip addr del 192.168.88.20$i/24 dev eth1; done) and run
CLAB_EXEC="docker exec" ./check.sh: every line must say PASS.
If something goes wrong¶
| Symptom | Likely cause | Fix |
|---|---|---|
invalid or unexpected argument |
v6 syntax with two gateways in one route | One route per gateway (Step 1) |
No + flag, only one route active |
Different distances | /ip route set [find dst-address=192.168.89.0/24] distance=1 |
| All eight sources take the same path | Bad luck with the hash (rare) | Try more sources (.209, .210...) |
| The route via B never goes inactive | No check-gateway on it |
Step 2 |
| After disabling r3's ether2 some pings fail for ~20 s | Normal: check-gateway needs two missed pings | Wait; that is the detection time |
traceroute -s says "Cannot assign requested address" |
The extra address was not added | ip -br addr show eth1 and add it |
Clean up¶
Key takeaways¶
- ECMP uses several routes to the same destination with the same distance at the same time; RouterOS marks them with
+. - In RouterOS v7 you create ECMP with one route per gateway; the v6
gateway=A,Bsyntax is rejected. - The router picks a path per flow with a hash; in v7 the default (
l3) uses source and destination address, so one conversation stays on one path. - The usable next hops are copied into the FIB, the table the router really forwards with.
- check-gateway=ping removes a dead path after two missed pings (about 20 s) and restores it when the gateway answers again.
Quick check¶
1. When does RouterOS use two routes to the same destination at the same time?
- When one of them is more specific than the other
- When they are equally specific and have the same distance
- When one is static and the other dynamic
- Never: only one route per destination can be active
That is ECMP: same destination, same distance. Both routes stay active and get the + flag. A more
specific route would simply win, and a lower distance would win too.
2. How do you create an ECMP route to 192.168.89.0/24 via 10.0.0.12 and 10.0.0.13 in RouterOS v7?
- One route with gateway=10.0.0.12,10.0.0.13
- Two routes with the same destination and distance, one per gateway
- One route with gateway=10.0.0.12 and ecmp=yes
- Two routes with distance 1 and distance 2
RouterOS v7 rejects the v6 list syntax. You add one route per gateway, same destination, same distance, and RouterOS groups them into ECMP.
3. With the default hash policy, why does pc1 always reach pc2 through the same path?
- Because ECMP only works for Internet traffic
- Because the first route always wins
- Because the path is chosen from the source and destination addresses, which never change for that pair
- Because pc2 only answers through one router
The hash is computed from the source and destination addresses (l3 policy). Same pair, same hash, same
path. That keeps the packets of a conversation in order.
4. What does check-gateway=ping do on an ECMP route whose gateway stops answering?
- It deletes the route from the configuration
- It marks only that route inactive, and the other paths keep working
- It disables every route to that destination
- It reboots the router to recover the gateway
After two missed pings the route is marked inactive and leaves the ECMP group. The other routes carry all the traffic. When the gateway answers again, the route returns by itself.
5. What is the FIB?
- The list of firewall rules
- A backup copy of the routing table
- The table of best routes and next hops the router actually uses to forward packets
- The list of interfaces in a bridge
The FIB (Forwarding Information Base) is built from the best active routes. In ECMP, all reachable next hops of the group are copied into it, so the router can use them together.
6. An office router has ECMP towards two Internet links. Pick the two statements that are true.
- Different laptops can end up using different links
- Every single download is split packet by packet over both links
- If one link's gateway dies and check-gateway is set, all traffic moves to the other link
- Both routes must have different distances
ECMP shares the load per flow: different address pairs hash to different links, but one conversation stays on one link. With check-gateway, a dead link is removed and the other carries everything.
Next: ECMP and check-gateway only notice a dead gateway. What if the gateway is fine but the provider behind it is broken? The answer is recursive routing.