> 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/1-basic-redistribution.md).

# 1) Basic Redistribution

### 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/0NACZzlaj0jClzFjXjaH" alt=""><figcaption></figcaption></figure>

All routing (static routes, OSPFv2, and BGP) is already setup.

Configure R1 to redistribute all static routes into OSPF. Routes should appear as OSPF E1 with metric 10.

### Answer

<details>

<summary>Expand to reveal</summary>

```
edit policy-options policy-statement STATIC_TO_OSPF 
set from protocol static
set then metric 10
set then external type 1
set then accept

top
set protocols ospf export STATIC_TO_OSPF
```

</details>

### Explanation

<details>

<summary>Expand to reveal</summary>

In Junos, route redistribution is accomplished using route policies. These are configured under the `policy-option policy-statement` configuration hierarchy.

\
You'll notice that the syntax is very similar to firewall filters. You use `from` to define the matching conditions, and `then` to define the actions. You can **match** things like the source protocol, route tag, prefix, etc. You can take **actions** such as accepting a route (passing it through/advertising it), rejecting a route (dropping it), set values such as local-pref, next-hop-self, tag, community, metric, etc.

\
Just like firewall filters, the terms of a routing policy are evaluated from the top down. Also, the behavior of multiple match conditions is the same as you are familiar with in firewall filters. Multiple match conditions of different items is a logical `AND`, while multiple match conditions of the same item is a logical `OR`.

\
There are currently three static routes on R1, which we want to redistribute into OSPF.

```
set routing-options static route 10.0.0.0/16 discard
set routing-options static route 10.0.1.0/24 discard
set routing-options static route 10.2.0.0/16 discard
```

\
We first create a route-policy that simply matches these static routes, and sets the route-type to E1 and metric to 10:

```
edit policy-options policy-statement STATIC_TO_OSPF 
set from protocol static
set then metric 10
set then external type 1
set then accept
```

\
To apply the policy, you configure an `export` statement under the routing protocol. In Junos, route import and export is from the perspective of the routing table (RIB). We are exporting routes from the RIB into OSPF, therefore we apply the routing policy under OSPF in the `export` direction:

```
set protocols ospf export STATIC_TO_OSPF
```

\
As a note, an `import` policy would be used under a protocol such as BGP for filtering received routes from a peer. This would filter routes received from a BGP peer as they are imported into the RIB.

\
We should see that R1 has created the Type 5 LSAs with type=E1 and metric=10:

```
admin@R2> show ospf database external detail    
    OSPF AS SCOPE link state database
 Type       ID               Adv Rtr           Seq      Age  Opt  Cksum  Len 
Extern   10.0.0.0         10.0.0.1         0x80000001    35  0x22 0xfe15  36
  mask 255.255.0.0
  Topology default (ID 0)
    Type: 1, Metric: 10, Fwd addr: 0.0.0.0, Tag: 0.0.0.0
Extern   10.0.1.0         10.0.0.1         0x80000001    35  0x22 0xf31f  36
  mask 255.255.255.0
  Topology default (ID 0)
    Type: 1, Metric: 10, Fwd addr: 0.0.0.0, Tag: 0.0.0.0
Extern   10.2.0.0         10.0.0.1         0x80000001    35  0x22 0xe62b  36
  mask 255.255.0.0
  Topology default (ID 0)
    Type: 1, Metric: 10, Fwd addr: 0.0.0.0, Tag: 0.0.0.0
```

</details>

### Further Reading

<https://www.youtube.com/watch?v=1CnVRmEejpY&list=PLDQaRcbiSnqHAGz-wapjtd3zQxUg-a8dU&index=18>

<https://www.juniper.net/documentation/us/en/software/junos/routing-policy/topics/concept/policy-routing-policies-overview.html>
