You can find materials for Lab II in the ospf directory. In this lab, we need to connect 4 routers in the same AS using the OSPF protocol.
Note
We use OSPF version 2 defined by RFC 2328 in this lab. You need to refer to the OSPFv2 document. OSPFv3 is defined for the IPv6 network and is not covered by this lab. You can find more information about OSPFv3 in RFC 5340.
Lab 2 Target Network Topology
OSPF Configurations
OSPF Routing
Deploy the lab environment using the following command:
❯ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES1a4b4b5e367f ceos:4.28.3 "bash -c '/mnt/flash…" 56 seconds ago Up 55 seconds R3f658786bc521 ceos:4.28.3 "bash -c '/mnt/flash…" 56 seconds ago Up 55 seconds R4cf0f039c9682 ceos:4.28.3 "bash -c '/mnt/flash…" 56 seconds ago Up 55 seconds R2872ca28f383a ceos:4.28.3 "bash -c '/mnt/flash…" 56 seconds ago Up 55 seconds R1
Checking the routing table before any configurations, we can find that each router contains only connected routes as expected.
R1>show ip route
VRF: default
Codes: C - connected, S - static, K - kernel,
O - OSPF, IA - OSPF inter area, E1 - OSPF external type 1,
E2 - OSPF external type 2, N1 - OSPF NSSA external type 1,
N2 - OSPF NSSA external type2, B - Other BGP Routes,
B I - iBGP, B E - eBGP, R - RIP, I L1 - IS-IS level 1,
I L2 - IS-IS level 2, O3 - OSPFv3, A B - BGP Aggregate,
A O - OSPF Summary, NG - Nexthop Group Static Route,
V - VXLAN Control Service, M - Martian,
DH - DHCP client installed default route,
DP - Dynamic Policy Route, L - VRF Leaked,
G - gRIBI, RC - Route Cache Route
Gateway of last resort is not set
C 1.1.1.0/24 is directly connected, Loopback0
C 10.1.1.0/24 is directly connected, Ethernet2
C 10.1.4.0/24 is directly connected, Ethernet1
R2>show ip route
VRF: default
Codes: C - connected, S - static, K - kernel,
O - OSPF, IA - OSPF inter area, E1 - OSPF external type 1,
E2 - OSPF external type 2, N1 - OSPF NSSA external type 1,
N2 - OSPF NSSA external type2, B - Other BGP Routes,
B I - iBGP, B E - eBGP, R - RIP, I L1 - IS-IS level 1,
I L2 - IS-IS level 2, O3 - OSPFv3, A B - BGP Aggregate,
A O - OSPF Summary, NG - Nexthop Group Static Route,
V - VXLAN Control Service, M - Martian,
DH - DHCP client installed default route,
DP - Dynamic Policy Route, L - VRF Leaked,
G - gRIBI, RC - Route Cache Route
Gateway of last resort is not set
C 2.2.2.0/24 is directly connected, Loopback0
C 10.1.1.0/24 is directly connected, Ethernet1
C 10.1.2.0/24 is directly connected, Ethernet2
R3>show ip route
VRF: default
Codes: C - connected, S - static, K - kernel,
O - OSPF, IA - OSPF inter area, E1 - OSPF external type 1,
E2 - OSPF external type 2, N1 - OSPF NSSA external type 1,
N2 - OSPF NSSA external type2, B - Other BGP Routes,
B I - iBGP, B E - eBGP, R - RIP, I L1 - IS-IS level 1,
I L2 - IS-IS level 2, O3 - OSPFv3, A B - BGP Aggregate,
A O - OSPF Summary, NG - Nexthop Group Static Route,
V - VXLAN Control Service, M - Martian,
DH - DHCP client installed default route,
DP - Dynamic Policy Route, L - VRF Leaked,
G - gRIBI, RC - Route Cache Route
Gateway of last resort is not set
C 3.3.3.0/24 is directly connected, Loopback0
C 10.1.3.0/24 is directly connected, Ethernet2
C 10.1.4.0/24 is directly connected, Ethernet1
R4>show ip route
VRF: default
Codes: C - connected, S - static, K - kernel,
O - OSPF, IA - OSPF inter area, E1 - OSPF external type 1,
E2 - OSPF external type 2, N1 - OSPF NSSA external type 1,
N2 - OSPF NSSA external type2, B - Other BGP Routes,
B I - iBGP, B E - eBGP, R - RIP, I L1 - IS-IS level 1,
I L2 - IS-IS level 2, O3 - OSPFv3, A B - BGP Aggregate,
A O - OSPF Summary, NG - Nexthop Group Static Route,
V - VXLAN Control Service, M - Martian,
DH - DHCP client installed default route,
DP - Dynamic Policy Route, L - VRF Leaked,
G - gRIBI, RC - Route Cache Route
Gateway of last resort is not set
C 4.4.4.0/24 is directly connected, Loopback0
C 10.1.2.0/24 is directly connected, Ethernet1
C 10.1.3.0/24 is directly connected, Ethernet2
Let's start the configuration from R1 and R2. Use the router ospf <process_id> command to create an OSPFv2 process and enter its configuration mode.
Different from BGP which uses TCP as its transport protocol, OSPF delivers data using raw IP packets. As a consequence, instead of specifying the addresses of neighbors, we need to assign local addresses to OSPF areas within which OSPF advertises routes. We use one single area in this lab, but in practice areas are important to reduce the size of the advertised message and ensure in-time convergence of the underlying link-state algorithm.
R1(config-router-ospf)#show ip ospf neighborNeighbor ID Instance VRF Pri State Dead Time Address Interface2.2.2.2 1 default 1 FULL/DR 00:00:34 10.1.1.2 Ethernet2
show ip ospf database gives internal details of the link state routing protocols.
R1(config-router-ospf)#show ip ospf database OSPF Router with ID(1.1.1.1) (Instance ID 1) (VRF default) Router Link States (Area 0.0.0.0)Link ID ADV Router Age Seq# Checksum Link count2.2.2.2 2.2.2.2 380 0x80000003 0x1fa 11.1.1.1 1.1.1.1 379 0x80000004 0x3dc6 1 Network Link States (Area 0.0.0.0)Link ID ADV Router Age Seq# Checksum10.1.1.2 2.2.2.2 380 0x80000001 0x2ceb
We need to configure OSPF to distribute routing to their local interface using redistribute connected.
R1(config-router-ospf)#show ip route
VRF: default
Codes: C - connected, S - static, K - kernel,
O - OSPF, IA - OSPF inter area, E1 - OSPF external type 1,
E2 - OSPF external type 2, N1 - OSPF NSSA external type 1,
N2 - OSPF NSSA external type2, B - Other BGP Routes,
B I - iBGP, B E - eBGP, R - RIP, I L1 - IS-IS level 1,
I L2 - IS-IS level 2, O3 - OSPFv3, A B - BGP Aggregate,
A O - OSPF Summary, NG - Nexthop Group Static Route,
V - VXLAN Control Service, M - Martian,
DH - DHCP client installed default route,
DP - Dynamic Policy Route, L - VRF Leaked,
G - gRIBI, RC - Route Cache Route
Gateway of last resort is not set
C 1.1.1.0/24 is directly connected, Loopback0
O E2 2.2.2.0/24 [110/1] via 10.1.1.2, Ethernet2
C 10.1.1.0/24 is directly connected, Ethernet2
O E2 10.1.2.0/24 [110/1] via 10.1.1.2, Ethernet2
C 10.1.4.0/24 is directly connected, Ethernet1
R2#show ip route
VRF: default
Codes: C - connected, S - static, K - kernel,
O - OSPF, IA - OSPF inter area, E1 - OSPF external type 1,
E2 - OSPF external type 2, N1 - OSPF NSSA external type 1,
N2 - OSPF NSSA external type2, B - Other BGP Routes,
B I - iBGP, B E - eBGP, R - RIP, I L1 - IS-IS level 1,
I L2 - IS-IS level 2, O3 - OSPFv3, A B - BGP Aggregate,
A O - OSPF Summary, NG - Nexthop Group Static Route,
V - VXLAN Control Service, M - Martian,
DH - DHCP client installed default route,
DP - Dynamic Policy Route, L - VRF Leaked,
G - gRIBI, RC - Route Cache Route
Gateway of last resort is not set
O E2 1.1.1.0/24 [110/1] via 10.1.1.1, Ethernet1
C 2.2.2.0/24 is directly connected, Loopback0
C 10.1.1.0/24 is directly connected, Ethernet1
C 10.1.2.0/24 is directly connected, Ethernet2
O E2 10.1.4.0/24 [110/1] via 10.1.1.1, Ethernet1
The two new routes are learned from OSPF (marked as O) and are external type 2 routes (marked as E2).
Note
If you are curious about the difference between the external type 1 (E1) route and external type 2 route (E2). When calculating the cost of a route, type 2 routes ignore the costs of all internal links while type 1 does not.
Note that 10.1.2.0/24 subnet is incorrectly regarded as an external route by R1 because we have not assigned them to OSPF area 0.
R1(config-router-ospf)#show ip route
VRF: default
Codes: C - connected, S - static, K - kernel,
O - OSPF, IA - OSPF inter area, E1 - OSPF external type 1,
E2 - OSPF external type 2, N1 - OSPF NSSA external type 1,
N2 - OSPF NSSA external type2, B - Other BGP Routes,
B I - iBGP, B E - eBGP, R - RIP, I L1 - IS-IS level 1,
I L2 - IS-IS level 2, O3 - OSPFv3, A B - BGP Aggregate,
A O - OSPF Summary, NG - Nexthop Group Static Route,
V - VXLAN Control Service, M - Martian,
DH - DHCP client installed default route,
DP - Dynamic Policy Route, L - VRF Leaked,
G - gRIBI, RC - Route Cache Route
Gateway of last resort is not set
C 1.1.1.0/24 is directly connected, Loopback0
O E2 2.2.2.0/24 [110/1] via 10.1.1.2, Ethernet2
C 10.1.1.0/24 is directly connected, Ethernet2
O 10.1.2.0/24 [110/20] via 10.1.1.2, Ethernet2
C 10.1.4.0/24 is directly connected, Ethernet1
R2(config-router-ospf)#show ip route
VRF: default
Codes: C - connected, S - static, K - kernel,
O - OSPF, IA - OSPF inter area, E1 - OSPF external type 1,
E2 - OSPF external type 2, N1 - OSPF NSSA external type 1,
N2 - OSPF NSSA external type2, B - Other BGP Routes,
B I - iBGP, B E - eBGP, R - RIP, I L1 - IS-IS level 1,
I L2 - IS-IS level 2, O3 - OSPFv3, A B - BGP Aggregate,
A O - OSPF Summary, NG - Nexthop Group Static Route,
V - VXLAN Control Service, M - Martian,
DH - DHCP client installed default route,
DP - Dynamic Policy Route, L - VRF Leaked,
G - gRIBI, RC - Route Cache Route
Gateway of last resort is not set
O E2 1.1.1.0/24 [110/1] via 10.1.1.1, Ethernet1
C 2.2.2.0/24 is directly connected, Loopback0
C 10.1.1.0/24 is directly connected, Ethernet1
C 10.1.2.0/24 is directly connected, Ethernet2
O 10.1.4.0/24 [110/20] via 10.1.1.1, Ethernet1
We can configure R3 and R4 following identical steps.
R1>show ip route
VRF: default
Codes: C - connected, S - static, K - kernel,
O - OSPF, IA - OSPF inter area, E1 - OSPF external type 1,
E2 - OSPF external type 2, N1 - OSPF NSSA external type 1,
N2 - OSPF NSSA external type2, B - Other BGP Routes,
B I - iBGP, B E - eBGP, R - RIP, I L1 - IS-IS level 1,
I L2 - IS-IS level 2, O3 - OSPFv3, A B - BGP Aggregate,
A O - OSPF Summary, NG - Nexthop Group Static Route,
V - VXLAN Control Service, M - Martian,
DH - DHCP client installed default route,
DP - Dynamic Policy Route, L - VRF Leaked,
G - gRIBI, RC - Route Cache Route
Gateway of last resort is not set
C 1.1.1.0/24 is directly connected, Loopback0
O E2 2.2.2.0/24 [110/1] via 10.1.1.2, Ethernet2
O E2 3.3.3.0/24 [110/1] via 10.1.4.3, Ethernet1
O E2 4.4.4.0/24 [110/1] via 10.1.4.3, Ethernet1
via 10.1.1.2, Ethernet2
C 10.1.1.0/24 is directly connected, Ethernet2
O 10.1.2.0/24 [110/20] via 10.1.1.2, Ethernet2
O 10.1.3.0/24 [110/20] via 10.1.4.3, Ethernet1
It's interesting to find that there are two ways to reach R4 from R1. Which one will be used? We can find out by using traceroute command.
R1>traceroute 4.4.4.4traceroute to 4.4.4.4 (4.4.4.4), 30 hops max, 60 byte packets 1 10.1.1.2 (10.1.1.2) 0.055 ms 0.016 ms 0.018 ms 2 4.4.4.4 (4.4.4.4) 0.051 ms 0.029 ms 0.031 ms
We will learn how to tune the routing table using path costs in the next section.
Path Cost
OSPF prefers a path with lower "cost". The cost of a path is the sum of the costs of all links it traverses. Generally speaking, link with larger capacity has lower cost. When all links have an identical bandwidth, paths with the least hops win. We can change the cost of an interface manually using the command ip ospf cost to tune the routing decision.
Let's change the path cost of Ethernet2 on R1 to 100, and see what will happen.
Check the routing table of R1 again, we will find that there is only one route to R4 now. The default cost of a 1000Mbps link is 0.01 by default. So the path R1 -> R3 -> R4 has a much lower cost than R1 -> R2 -> R4 now, making OSPF prefers the former one.
R1>show ip route
VRF: default
Codes: C - connected, S - static, K - kernel,
O - OSPF, IA - OSPF inter area, E1 - OSPF external type 1,
E2 - OSPF external type 2, N1 - OSPF NSSA external type 1,
N2 - OSPF NSSA external type2, B - Other BGP Routes,
B I - iBGP, B E - eBGP, R - RIP, I L1 - IS-IS level 1,
I L2 - IS-IS level 2, O3 - OSPFv3, A B - BGP Aggregate,
A O - OSPF Summary, NG - Nexthop Group Static Route,
V - VXLAN Control Service, M - Martian,
DH - DHCP client installed default route,
DP - Dynamic Policy Route, L - VRF Leaked,
G - gRIBI, RC - Route Cache Route
Gateway of last resort is not set
C 1.1.1.0/24 is directly connected, Loopback0
O E2 2.2.2.0/24 [110/1] via 10.1.4.3, Ethernet1
O E2 3.3.3.0/24 [110/1] via 10.1.4.3, Ethernet1
O E2 4.4.4.0/24 [110/1] via 10.1.4.3, Ethernet1
C 10.1.1.0/24 is directly connected, Ethernet2
O 10.1.2.0/24 [110/30] via 10.1.4.3, Ethernet1
O 10.1.3.0/24 [110/20] via 10.1.4.3, Ethernet1
C 10.1.4.0/24 is directly connected, Ethernet1
Similarly, R3 now prefers R4 as the intermediate router to reach R2.
But what happened to R4? Nothing changes indeed. We will find that it still has two routes to R1.
R4>show ip route
VRF: default
Codes: C - connected, S - static, K - kernel,
O - OSPF, IA - OSPF inter area, E1 - OSPF external type 1,
E2 - OSPF external type 2, N1 - OSPF NSSA external type 1,
N2 - OSPF NSSA external type2, B - Other BGP Routes,
B I - iBGP, B E - eBGP, R - RIP, I L1 - IS-IS level 1,
I L2 - IS-IS level 2, O3 - OSPFv3, A B - BGP Aggregate,
A O - OSPF Summary, NG - Nexthop Group Static Route,
V - VXLAN Control Service, M - Martian,
DH - DHCP client installed default route,
DP - Dynamic Policy Route, L - VRF Leaked,
G - gRIBI, RC - Route Cache Route
Gateway of last resort is not set
O E2 1.1.1.0/24 [110/1] via 10.1.2.2, Ethernet1
via 10.1.3.3, Ethernet2
O E2 2.2.2.0/24 [110/1] via 10.1.2.2, Ethernet1
O E2 3.3.3.0/24 [110/1] via 10.1.3.3, Ethernet2
C 4.4.4.0/24 is directly connected, Loopback0
O 10.1.1.0/24 [110/20] via 10.1.2.2, Ethernet1
C 10.1.2.0/24 is directly connected, Ethernet1
C 10.1.3.0/24 is directly connected, Ethernet2
O 10.1.4.0/24 [110/20] via 10.1.3.3, Ethernet2
So remember that path cost is unidirectional. It is not symmetric. When we change the link cost from R1 to R2, the link cost from R2 to R1 is not changed.
With careful planning, we can enforce desired routing rules with implicit and distributed path costs. It partially explains why OSPF is only applied as an intra-AS routing protocol. When the scale of the network increases, it is hard to manage the routing table in such a distributed manner.
R2>enableR2#configureR2(config)#router ospf 1R2(config-router-ospf)#network 10.1.1.2/24 area 0.0.0.0R2(config-router-ospf)#network 10.1.2.2/24 area 0.0.0.0R2(config-router-ospf)#redistribute connectedR2(config-router-ospf)#exitR2(config)#exitR2#exit
R3>enableR3#configureR3(config)#router ospf 1R3(config-router-ospf)#network 10.1.4.3/24 area 0.0.0.0R3(config-router-ospf)#network 10.1.3.3/24 area 0.0.0.0R3(config-router-ospf)#redistribute connectedR3(config-router-ospf)#exitR3(config)#exitR3#exit
R4>enableR4#configureR4(config)#router ospf 1R4(config-router-ospf)#network 10.1.2.4/24 area 0.0.0.0R4(config-router-ospf)#network 10.1.3.4/24 area 0.0.0.0R4(config-router-ospf)#redistribute connectedR4(config-router-ospf)#exitR4(config)#exitR4#exit
Test
Once the configuration is done, we can test the connectivity between the four routers using the script test.py in the ospy directory.