Routing – OSPF, BGP & Forwarding tables

ipip-forwarding-tableospfrouterrouting

I'm little bit confusing about the flow of things that happen during a voyage of packet in the internet.
my basic question is : What is the connection between OSPF and forwarding tables?

Suppose there are lets say 10 ASes, each AS has some routers and switches within it. Now, host A in some AS want to send IP datagram to host B which is in other AS. Now, first of all, the AS use OSPF protocol. By this, each router know what is the "cost" of send datagram to the another routers in the AS?
And another question: when datagram arrives to a router, and in the forwarding table there is no match, it floods to all of its interfaces (?) , but, OSPF give each router the best path it need to choose, so why forwarding tables are needed anyway? i'm so confused and can't find connections between things.

(sorry about the english, it is not my native language)

Best Answer

Routing protocols, in general, are used to populate the routing tables and not to forward packets.

Between two AS it is generally BGP that is used to exchange routes, and within an AS, it can be OSPF, but could also be IS-IS, EIGRP or any routing protocol.

A given router can use several routing protocols at the same time.

Lets say a router is configured to use OSPF and BGP.

The router will keep in memory different routing tables:

  • one for routes learn trough OSPF
  • one for routes learn trough BGP
  • one for routes added statically by the router administrator
  • one for network directly connected

The forwarding table is built by selecting routes within all those tables.

For each network that exists in at least one routing table, the router select the best one and put it in its forwarding table.

When the router receive a packet, it looks only in its forwarding table to decide where to send it. Where the route comes from has no importance at this point.