> 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/3-ospf.md).

# 3) OSPF

### Pre-Work

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

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

### Lab

R2 and R3 already have OSPFv2 and OSPFv3 configured. Try not to use them for reference, and configure R1 as follows:

* Configure ge-0/0/0, ge-0/0/3, and Lo0 for OSPFv2 and OSPFv3
  * ge-0/0/0 should be network type point-to-point
  * ge-0/0/3 should be passive
* Set the router ID to 10.0.0.1 (for both OSPFv2 and OSPFv3)
* All interfaces should belong to area 0

R1 should form adjacencies with R2 over OSPFv2 and OSPFv3, and be able to ping the loopbacks of R2 and R3 sourced from ge-0/0/3 (`10.1.100.1` and `2001:db8:1:100::1`).

```
admin@R1> ping 2.2.2.2 source 10.1.100.1  
PING 2.2.2.2 (2.2.2.2): 56 data bytes
64 bytes from 2.2.2.2: icmp_seq=0 ttl=64 time=1.724 ms
64 bytes from 2.2.2.2: icmp_seq=1 ttl=64 time=1.669 ms

admin@R1> ping 2001:db8::3 source 2001:db8:1:100::1 
PING6(56=40+8+8 bytes) 2001:db8:1:100::1 --> 2001:db8::3
16 bytes from 2001:db8::3, icmp_seq=0 hlim=63 time=2.504 ms
16 bytes from 2001:db8::3, icmp_seq=1 hlim=63 time=2.639 ms
```

### Answer

<details>

<summary>Expand to reveal</summary>

```
set protocols ospf area 0 interface ge-0/0/0.0 interface-type p2p  
set protocols ospf area 0 interface ge-0/0/3.0 passive  
set protocols ospf area 0 interface lo0.0                            
set protocols ospf3 area 0 interface ge-0/0/0.0 interface-type p2p  
set protocols ospf3 area 0 interface ge-0/0/3.0 passive   
set protocols ospf3 area 0 interface lo0.0                            
set routing-options router-id 10.0.0.1
```

</details>

### Explanation

<details>

<summary>Expand to reveal</summary>

In Junos, OSPF and OSPFv3 are configured under `protocols ospf` and `protocols ospf3` respectively.&#x20;

\
The router ID cannot be set under individual protocols in Junos. Instead, the router ID is set globally and takes effect for all protocols.

```
set routing-options router-id 10.0.0.1
```

\
We should see that R1 has an adjacency with R2 over OSPFv2 and OSPFv3:

```
admin@R1> show ospf neighbor 
Address          Interface              State           ID               Pri  Dead
10.1.2.2         ge-0/0/0.0             Full            10.0.0.2         128    32

admin@R1> show ospf3 neighbor 
ID               Interface              State     Pri   Dead
10.0.0.2         ge-0/0/0.0             Full      128     37
  Neighbor-address fe80::aac1:abff:fe87:d32b
```

\
We can view the OSPF routes in the RIB using `protocol ospf`:

```
admin@R1> show route protocol ospf   

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

2.2.2.2/32         *[OSPF/10] 00:05:04, metric 1
                    >  to 10.1.2.2 via ge-0/0/0.0
3.3.3.3/32         *[OSPF/10] 00:05:04, metric 2
                    >  to 10.1.2.2 via ge-0/0/0.0
10.2.3.0/24        *[OSPF/10] 00:05:04, metric 2
                    >  to 10.1.2.2 via ge-0/0/0.0
224.0.0.5/32       *[OSPF/10] 00:05:14, metric 1
                       MultiRecv

mgmt_junos.inet.0: 3 destinations, 3 routes (3 active, 0 holddown, 0 hidden)

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

2001:db8::2/128    *[OSPF3/10] 00:05:09, metric 1
                    >  to fe80::aac1:abff:fe87:d32b via ge-0/0/0.0
2001:db8::3/128    *[OSPF3/10] 00:05:09, metric 2
                    >  to fe80::aac1:abff:fe87:d32b via ge-0/0/0.0
2001:db8:2:3::/64  *[OSPF3/10] 00:05:09, metric 2
                    >  to fe80::aac1:abff:fe87:d32b via ge-0/0/0.0
ff02::5/128        *[OSPF3/10] 00:05:14, metric 1
                       MultiRecv

mgmt_junos.inet6.0: 4 destinations, 4 routes (4 active, 0 holddown, 0 hidden)

admin@R1> 
```

\
Note that we can use either `protocol ospf` or `protocol ospf3` to view OSPFv3 routes in the `inet6.0` table.

```
admin@R1> show route table inet6.0 protocol ospf      

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

2001:db8::2/128    *[OSPF3/10] 00:05:52, metric 1
                    >  to fe80::aac1:abff:fe87:d32b via ge-0/0/0.0
2001:db8::3/128    *[OSPF3/10] 00:05:52, metric 2
                    >  to fe80::aac1:abff:fe87:d32b via ge-0/0/0.0
2001:db8:2:3::/64  *[OSPF3/10] 00:05:52, metric 2
                    >  to fe80::aac1:abff:fe87:d32b via ge-0/0/0.0
ff02::5/128        *[OSPF3/10] 00:05:57, metric 1
                       MultiRecv

admin@R1> show route table inet6.0 protocol ospf3    

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

2001:db8::2/128    *[OSPF3/10] 00:05:54, metric 1
                    >  to fe80::aac1:abff:fe87:d32b via ge-0/0/0.0
2001:db8::3/128    *[OSPF3/10] 00:05:54, metric 2
                    >  to fe80::aac1:abff:fe87:d32b via ge-0/0/0.0
2001:db8:2:3::/64  *[OSPF3/10] 00:05:54, metric 2
                    >  to fe80::aac1:abff:fe87:d32b via ge-0/0/0.0
ff02::5/128        *[OSPF3/10] 00:05:59, metric 1
                       MultiRecv
```

\
We can inspect the OSPF database as well:

```
admin@R1> show ospf database 

    OSPF database, Area 0.0.0.0
 Type       ID               Adv Rtr           Seq      Age  Opt  Cksum  Len 
Router  *10.0.0.1         10.0.0.1         0x80000002    37  0x22 0xe56a  72
Router   10.0.0.2         10.0.0.2         0x80000003    43  0x22 0xf685  84
Router   10.0.0.3         10.0.0.3         0x80000002    73  0x22 0xceef  60

```

\
As well as the OSPFv3 database:

```
admin@R1> show ospf3 database 

    OSPF3 database, Area 0.0.0.0
 Type       ID               Adv Rtr           Seq         Age  Cksum  Len 
Router     *0.0.0.0          10.0.0.1         0x80000001    69  0xeaf9  40
Router      0.0.0.0          10.0.0.2         0x80000002    70  0x8e31  56
Router      0.0.0.0          10.0.0.3         0x80000001    92  0xf0f0  40
IntraArPfx *0.0.0.1          10.0.0.1         0x80000001    69  0x9875  76
IntraArPfx  0.0.0.1          10.0.0.2         0x80000002    92  0x4abc  76
IntraArPfx  0.0.0.1          10.0.0.3         0x80000002    93  0xb289  64

    OSPF3 Link-Local database, interface ge-0/0/0.0 Area 0.0.0.0
 Type       ID               Adv Rtr           Seq         Age  Cksum  Len 
Link       *0.0.0.2          10.0.0.1         0x80000001    69  0x3c51  56
Link        0.0.0.2          10.0.0.2         0x80000001    92  0x5bd8  56

    OSPF3 Link-Local database, interface lo0.0 Area 0.0.0.0
 Type       ID               Adv Rtr           Seq         Age  Cksum  Len 
Link       *0.0.0.1          10.0.0.1         0x80000001    69  0x7e86  44
```

\
We can get details of the LSAs:

```
admin@R1> show ospf database router advertising-router self detail 

    OSPF database, Area 0.0.0.0
 Type       ID               Adv Rtr           Seq      Age  Opt  Cksum  Len 
Router  *10.0.0.1         10.0.0.1         0x80000002   245  0x22 0xe56a  72
  bits 0x0, link count 4
  id 10.0.0.2, data 10.1.2.1, Type PointToPoint (1)
    Topology count: 0, Default metric: 1
  id 10.1.2.0, data 255.255.255.0, Type Stub (3)
    Topology count: 0, Default metric: 1
  id 10.1.100.0, data 255.255.255.0, Type Stub (3)
    Topology count: 0, Default metric: 1
  id 1.1.1.1, data 255.255.255.255, Type Stub (3)
    Topology count: 0, Default metric: 0
  Topology default (ID 0)
    Type: PointToPoint, Node ID: 10.0.0.2
      Metric: 1, Bidirectional


admin@R1> show ospf3 database router advertising-router self detail 

    OSPF3 database, Area 0.0.0.0
 Type       ID               Adv Rtr           Seq         Age  Cksum  Len 
Router     *0.0.0.0          10.0.0.1         0x80000001   286  0xeaf9  40
  bits 0x0, Options 0x33
  Type PointToPoint (1), Metric 1
      Loc-If-Id 2, Nbr-If-Id 2, Nbr-Rtr-Id 10.0.0.2
  Type: PointToPoint, Node ID: 10.0.0.2, Metric: 1, Bidirectional
```

\
Using `show ospf interface` we should see that `ge-0/0/3.0` is passive:

```
admin@R1> show ospf interface detail 
Interface           State   Area            DR ID           BDR ID          Nbrs
ge-0/0/0.0          PtToPt  0.0.0.0         0.0.0.0         0.0.0.0            1
  Type: P2P, Address: 10.1.2.1, Mask: 255.255.255.0, MTU: 1500, Cost: 1
  Adj count: 1
  Hello: 10, Dead: 40, ReXmit: 5, Not Stub
  Auth type: None
  Protection type: None
  Topology default (ID 0) -> Cost: 1
ge-0/0/3.0          DRother 0.0.0.0         0.0.0.0         0.0.0.0            0
  Type: LAN, Address: 10.1.100.1, Mask: 255.255.255.0, MTU: 1500, Cost: 1
  Adj count: 0, Passive   <--------------------------
  Hello: 10, Dead: 40, ReXmit: 5, Not Stub
  Auth type: None
  Protection type: None
  Topology default (ID 0) -> Passive, Cost: 1
lo0.0               DR      0.0.0.0         10.0.0.1        0.0.0.0            0
  Type: LAN, Address: 1.1.1.1, Mask: 255.255.255.255, MTU: 65535, Cost: 0
  DR addr: 1.1.1.1, Priority: 128
  Adj count: 0
  Hello: 10, Dead: 40, ReXmit: 5, Not Stub
  Auth type: None
  Protection type: None
  Topology default (ID 0) -> Cost: 0

admin@R1> 

admin@R1> show ospf3 interface detail 
Interface           State   Area            DR ID           BDR ID          Nbrs
ge-0/0/0.0          PtToPt  0.0.0.0         0.0.0.0         0.0.0.0            1
  Address fe80::aac1:abff:fec5:e483, Prefix-length 64
  OSPF3-Intf-index 2, Type P2P, MTU 1500, Cost 1
  Adj count: 1, Router LSA ID: 0
  Hello 10, Dead 40, ReXmit 5, Not Stub
  Protection type: None
ge-0/0/3.0          DRother 0.0.0.0         0.0.0.0         0.0.0.0            0
  Address fe80::aac1:abff:fef7:fb75, Prefix-length 64
  OSPF3-Intf-index 3, Type LAN, MTU 1500, Cost 1
  Adj count: 0, Router LSA ID: -, Passive  <--------------------------
  Hello 10, Dead 40, ReXmit 5, Not Stub
  Protection type: None
lo0.0               DR      0.0.0.0         10.0.0.1        0.0.0.0            0
  Address fe80::e00:f60f:fc53:a100, Prefix-length 128
  OSPF3-Intf-index 1, Type LAN, MTU 65535, Cost 0, Priority 128
  Adj count: 0, Router LSA ID: -
  DR addr fe80::e00:f60f:fc53:a100
  Hello 10, Dead 40, ReXmit 5, Not Stub
  Protection type: None
```

</details>

### Further Reading

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

<https://www.youtube.com/watch?v=q24QQ-B3QBw>

<https://www.juniper.net/documentation/us/en/software/junos/ospf/topics/topic-map/ospf-overview.html>
