> For the complete documentation index, see [llms.txt](https://jncia-workbook.gitbook.io/workbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jncia-workbook.gitbook.io/workbook/junos-routing-policy/6-ecmp.md).

# 6) ECMP

### Pre-Work

Load the config called **policy.cfg** using the **load\_config\_on\_nodes.py** script.

```
python3 load_config_on_nodes.py --lab_dir three-routers --config_filename policy.cfg
```

### Lab

<figure><img src="/files/PXyABVnEpc5mAFJ0b3wf" alt=""><figcaption></figcaption></figure>

Currently, R1 has one single path to R2's loopback address `2.2.2.2/32` in the FIB:

```
admin@R1> show route table inet.0 2.2.2.2/32                                  

inet.0: 10 destinations, 10 routes (10 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

2.2.2.2/32         *[OSPF/10] 00:00:27, metric 1
                    >  to 10.1.2.2 via ge-0/0/0.0
                       to 10.101.102.2 via ge-0/0/3.0

admin@R1> show route forwarding-table destination 2.2.2.2/32 table default    
Routing table: default.inet
Internet:
Destination        Type RtRef Next hop           Type Index    NhRef Netif
2.2.2.2/32         user     0 10.1.2.2           ucst      595     3 ge-0/0/0.0   <--------

admin@R1> 

```

Configure ECMP so that R1 will use both paths (`ge-0/0/0` and `ge-0/0/3`).

### Answer

<details>

<summary>Expand to reveal</summary>

```
set policy-options policy-statement ECMP then load-balance per-packet
set routing-options forwarding-table export ECMP
```

</details>

### Explanation

<details>

<summary>Expand to reveal</summary>

As mentioned in previous labs, Junos by default has ECMP turned off. When there are multiple equal-cost paths for a prefix, only one path is chosen (at random) and installed into the forwarding-table.

\
To enable ECMP, we use an export policy. The idea behind this is that routes are exported from the RIB to the FIB. (Remember that routing policies are always from the perspective of the RIB). So we apply an export policy on the FIB which sets `load-balance per-packet`. The `per-packet` syntax is historical - all modern devices will actually do per-flow load balancing. The use of a route policy for enabling ECMP allows you to granularly apply ECMP to only particular prefixes, if that is your goal.

\
The new syntax actually appears to be `per-flow`. What I have seen in documentation is `per-packet`, which is why I used it here.

```
[edit]
admin@R1# set policy-options policy-statement ECMP then load-balance per-?  
Possible completions:
  per-flow             Load balance on a per-flow basis
  per-packet           Load balance on a per-packet basis deprecated, use per-flow instead

```

\
Notice that we have no `term` and no `match` statement on our policy in this lab. We saw in a previous lab that when there is only one single term in the policy, we can omit the `term`. Also, when there is no `match` statement, all routes match. Optionally, you could match only routes from `protocol ospf`, or something similar.

```
set policy-options policy-statement ECMP then load-balance per-packet
set routing-options forwarding-table export ECMP
```

\
We should see that R1 now has two paths in its forwarding table for `2.2.2.2/32`:

```
admin@R1> show route forwarding-table destination 2.2.2.2/32 table default    
Routing table: default.inet
Internet:
Destination        Type RtRef Next hop           Type Index    NhRef Netif
2.2.2.2/32         user     0                    ulst  1048574     2
                              10.1.2.2           ucst      595     3 ge-0/0/0.0
                              10.101.102.2       ucst      596     3 ge-0/0/3.0
```

</details>

### Further Reading

<https://serverfault.com/questions/209657/ecmp-load-balancing-in-junos>

<https://www.juniper.net/documentation/us/en/software/junos/sampling-forwarding-monitoring/topics/concept/policy-configuring-per-packet-load-balancing.html>
