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

# 7) Selective Redistribution (Part 1)

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

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

Configure R1 to redistribute all static routes into OSPF. Use a route policy that only permits prefixes within 10.0.0.0/16, and including 10.0.0.0/16.

### Answer

<details>

<summary>Expand to reveal</summary>

```
edit policy-options policy-statement STATIC_TO_OSPF 
set from protocol static
set from route-filter 10.0.0.0/16 orlonger
set then accept

top
set protocols ospf export STATIC_TO_OSPF
```

</details>

### Explanation

<details>

<summary>Expand to reveal</summary>

Route policies allow us to have granular control over which prefixes are redistributed. In this lab, we use a `route-filter` to only permit prefixes within 10.0.0.0/16. A `route-filter` is defined "in-line" of the route policy.

```
edit policy-options policy-statement STATIC_TO_OSPF 
set from protocol static
set from route-filter 10.0.0.0/16 orlonger
set then accept
```

\
The `orlonger` keyword means that we allow any prefix within `10.0.0.0/16`, including the prefix `10.0.0.0/16`. `orlonger` is referring to the mask, meaning we allow a prefix within this subnet with mask /16 or longer than that (up to /32). There are several other options besides `orlonger`, listed in the table below:

| Keyword               | Meaning                                                                            | Example                                                                                                                                                                                                                                                                                          |
| --------------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `exact`               | Only the exact prefix.                                                             | `10.0.0.0/16 exact` matches 10.0.0.0/16 and nothing else                                                                                                                                                                                                                                         |
| `orlonger`            | Any mask that is longer than the prefix specified, including the prefix specified. | `10.0.0.0/16 orlonger` matches 10.0.0.0/16, 10.0.1.0/24, etc.                                                                                                                                                                                                                                    |
| `longer`              | Only prefixes that have a longer mask.                                             | `10.0.0.0/16 longer` matches 10.0.1.0/24, and does not match 10.0.0.0/16                                                                                                                                                                                                                         |
| `upto`                | Only prefixes with a mask up to the given value.                                   | `10.0.0.0/16 upto 24` would mean 10.0.0.0/16 matches, 10.0.1.0/24 matches, and 10.0.2.0/25 does not match.                                                                                                                                                                                       |
| `prefix-length-range` | Only prefixes with a mask within the range.                                        | `10.0.0.0/16 prefix-length-range 18 to 24` would mean 10.0.0.0/16 does not match, 10.0.0.0/18 does match, 10.0.1.0/24 does match, and 10.0.2.0/25 does not match.                                                                                                                                |
| `address-mask`        | Allows you to specify a non-contiguous mask, similar to IOS.                       | <p><code>10.0.0.0/24 address-mask 255.0.255.0</code> matches /24s in the format 10.x.0.0/24. For example it matches 10.1.0.0/24 but does not match 10.0.1.0/24. </p><p></p><p>The mask you use (for example <code>/24</code> here) is the exact mask the prefix must have in order to match.</p> |
| `through`             | Match a range of masks, but not subnets within that prefix.                        | `10.0.0.0/16 through 10.0.0.0/24` will only match 10.0.0.0/(16-24) exactly. 10.0.0.0/16 matches, 10.0.0.0/17 matches, etc. But 10.0.2.0/23 does not match.                                                                                                                                       |

\
We should see that R1 is only redistributing these two prefixes:

```
admin@R1> show ospf database external 
    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     6  0x22 0x1e7f  36
Extern  *10.0.1.0         10.0.0.1         0x80000001     6  0x22 0x1389  36
```

</details>

### Further Reading

<https://www.juniper.net/documentation/us/en/software/junos/routing-policy/topics/concept/policy-configuring-route-lists-for-use-in-routing-policy-match-conditions.html>
