Example: Configuring an OSPF Import Policy
This example shows how to create an OSPF import policy. OSPF import policies apply to external routes only. An external route is a route that is outside the OSPF autonomous system (AS).
Before you begin:
Configure the router identifiers for the devices in your OSPF network. See Example: Configuring an OSPF Router Identifier.
Control OSPF designated router election. See Example: Controlling OSPF Designated Router Election.
Configure a single-area OSPF network. See Example: Configuring a Single-Area OSPF Network .
External routes are learned by AS boundary routers. External routes can be advertised throughout the OSPF domain if you configure the AS boundary router to redistribute the route into OSPF. An external route might be learned by the AS boundary router from a routing protocol other than OSPF, or the external route might be a static route that you configure on the AS boundary router.
For OSPFv3, the link-state advertisement (LSA) is referred to as the interarea prefix LSA and performs the same function as a network-summary LSA performs for OSPFv2. An area border router (ABR) originates an interarea prefix LSA for each IPv6 prefix that must be advertised into an area.
OSPF import policy allows you to prevent external routes from being added to the routing tables of OSPF neighbors. The import policy does not impact the OSPF database. This means that the import policy has no impact on the link-state advertisements. The filtering is done only on external routes in OSPF. The intra-area and interarea routes are not considered for filtering. The default action is to accept the route when the route does not match the policy.
This example includes the following OSPF policy settings:
policy-statement—Defines the routing policy. You specify the name of the policy and further define the elements of the policy. The policy name must be unique and can contain letters, numbers, and hyphens ( - ) and be up to 255 characters long.
export—Applies the export policy you created to be evaluated when network summary LSAs are flooded into an area. In this example, the export policy is named export_static.
import—Applies the import policy you created to prevent external routes from being added to the routing table. In this example, the import policy is named filter_routes.
The devices you configure in this example represent the following functions:
R1—Device R1 is in area 0.0.0.0 and has a direct connection to device R2. R1 has an OSPF export policy configured. The export policy redistributes static routes from R1’s routing table into R1’s OSPF database. Because the static route is in R1’s OSPF database, the route is advertised in an LSA to R1’s OSPF neighbor. R1’s OSPF neighbor is device R2.
R2—Device R2 is in area 0.0.0.0 and has a direct connection to device R1. R2 has an OSPF import policy configured that matches the static route to the 10.0.16.0/30 network and prevents the static route from being installed in R2’s routing table. R2’s OSPF neighbor is device R1.
CLI Quick Configuration
To quickly configure an OSPF import policy, paste them into a text file, remove any line breaks, change any details necessary to match your network configuration, copy and paste the commands into the CLI at the  hierarchy level, and then enter commit from configuration mode.
Configuration on Device R1:
Configuration on Device R2:
To configure an OSPF import policy:
- Configure the interfaces.user@R1# set interfaces so-0/2/0 unit 0 family inet address 10.0.2.1/30user@R2# set interfaces so-0/2/0 unit 0 family inet address 10.0.2.2/30
- Enable OSPF on the interfaces.
For OSPFv3, include the ospf3 statement at the [edit protocols] hierarchy level.user@R1# set protocols ospf area 0.0.0.0 interface so-0/2/0user@R2# set protocols ospf area 0.0.0.0 interface so-0/2/0
- On R1, redistribute the static route into OSPF.
- On R2, configure the OSPF import policy.user@R2# set protocols ospf import filter_routesuser@R2# set policy-options policy-statement filter_routes from route-filter 10.0.16.0/30 exactuser@R2# set policy-options policy-statement filter_routes then reject
- If you are done configuring the devices, commit the configuration.user@host# commit
Confirm your configuration by entering the show interfaces, show policy-options, and show protocols ospf commands on the appropriate device. If the output does not display the intended configuration, repeat the instructions in this example to correct the configuration.
Output for R1:
Output for R2:
To confirm your OSPFv3 configuration, enter the show interfaces, show policy-options, show routing-options, and show protocols ospf3 commands on the appropriate device.
Confirm that the configuration is working properly.
Verifying the OSPF Database
Verify that OSPF is advertising the static route in the OSPF database.
From operational mode, enter the show ospf database for OSPFv2, and enter the show ospf3 database command for OSPFv3.
Verifying the Routing Table
Verify the entries in the routing table.
From operational mode, enter the show route command.