I have several questions on OSPF.
1 OSPF is a link-state prototol, so routers inside an AS only broadcast their link states to all the other routers.
I'm wondering if a router doesn't tell other routers its routing table, how can other routers know what packets should be destined to it?
for example, if a router A is an edge router(leaf router) which interfaces the subnet 10.0.2.1/24. Assume another router B receives a packet with destination IP 10.0.0.2.4. From OSPF, B knows the shortest path to A, but B doesn't know A is an edge router interfacing the subnet 10.0.2.1/24, so how will B route this packet?
2 if a router receives a packet with destination outside the AS, according to my understanding, the packet will follow the default route 0.0.0.0 and the router will route the packet to a ABR. but ususally an AS has several ABR, so how does a router select one from these ABRs?
Best Answer
OSPF is a link state protocol that uses multicast. It sends Link State Advertisements (LSAs) that are flooded.
Every router builds a tree by running SPF where the router itself is the root of the tree. In OSPF we have transit networks and stub networks. Transit networks are networks that are used for transit to reach networks while stub networks are the endpoints or leaves as you described it.
If we are in the same area then the router LSA (type-1) is examined to find the destination. Here is a router-LSA to reach the network of R1 which has a RID of 1.1.1.1.
R1 has a cost of 1 to this stub network. R2 can reach this network through the 12.12.12.0/24 transit network. So we need to add a cost of 10 which brings the total metric to 11.
This is an intra area route. For inter area routes OSPF actually behaves like a distance vector protocol because traffic is sent through the ABR. How can we identify an ABR?
The B bit is set in the OSPF header which makes a router an ABR.
This can be seen in a packet capture.
To find the metric of an inter area route the metric of the ABR to the destination + the metric of the local route to the ABR is added.
Here the cost is 10 to reach the two ABRs. Because the cost was 11 from the ABR to the destination that should mean that R4 has a metric of 21.
Which it is. Because there are two ABRs here with the same cost both routes are installed into the RIB/FIB. If we increase the cost to one ABR then only one entry will be installed.
There really is no concept of AS in OSPF but you can originate a default route and then the best metric would win. I recommend that you read through RFC 2328 and OSPF: Anatomy of an Internet Routing Protocol if you want more understanding of OSPF.