So welcome back, guys.
Next, we will going to discuss the concept of routing table and how does route lookup happens in the
routing table.
So remember that we have an L3 router and every L3 router has an L3 routing table.
Right?
And we already know that the content of L3 routing table are L3 routes.
Now we will discuss that how actually L3 router make use of its L3 routing table in order to decide
that what it has to do with the packet which it has just received from the previous router.
So you can see in this diagram we have an L3 router.
And suppose this L3 router has just received an IP packet on its one of the interface called Ethernet
one.
Right.
So now how does this L3 router decides that what it has to do with the packet, should it consume the
packet or should it forward the packet to the next router or should it forward the packet to a machine
in a direct local subnet?
Or should it silently discard the packet?
So the question arises that how does the layer three router will take one of these decisions?
On what basis will the layer three router will decide that what it has to do with the packet.
So simply router decides by looking up the matching entry in the layer three routing table.
So we have this layer three routing table and every L3 router has this routing table.
So based on the contents of this layer three routing table, the router takes one of the decisions regarding
what it has to do with the packet.
So now let us discuss in detail that how does Layer three router make use of its layer three routing
table when it receives an IP packet?
So guys, going forward now let us suppose that for a given router we have a layer three routing table.
Right.
So in the diagram I have shown you the routing table of some L three router.
Now suppose the L three router receives a packet whose destination IP address is 122.1.1.1.
Right.
So the destination IP address that is specified in the IP header of the packet received by the router
is 122.1.1.1.
Now for an l three router to decide that what it has to do with this packet, the router actually take
up the destination IP address specified in the IP header of the packet and performs l three route lookup
in its routing table.
Right.
So when it performs layer three root lookup in its routing table using destination IP address as a key.
This process produces the output and that output information is nothing, but it is the next hop information.
That is, it is the information which tells the router that how it should forward the packet.
So in this case the packet should be forwarded out of the local interface represented by OIF towards
the next hop IP address, which is represented by Gateway IP.
Right.
So whenever a router performs a root lookup in its local routing table using destination IP address
as a key, the router obtains the next hop information as an output.
So this is how the router would know that.
What is the next router to which it should forward the packet?
So now let us illustrate this with the help of an example.
So you can see that in this diagram.
I have shown you the routing table of a router.
So let's say it is a routing table.
Right now in this routing table.
You can see that I have some couple of entries.
All these entries are layer three routing information present in the layer three routing table.
So you can see that dust field and mask field together combines to form a destination mask.
Gateway is the next hop IP address and the local outgoing interface is represented by OIF.
So the first entity is dest and mask together forms the first entity of the layer three route.
The second entity is the gateway IP address, and the third entity is the local outgoing interface.
Remember the layer three routing information consists of main three entities.
Right.
So now going forward.
So now let us say that the router has received an IP packet from the previous router whose destination
IP address is 92.168 .5. ten.
Right.
So these are the four steps which the router uses in order to perform a route lookup in the routing
table.
Right.
So now let us apply these four steps and see that which entry in this routing table matches with this
destination IP address.
So let us start with the entry one.
That is apply mask to the input IP address.
So for entry one, the mask value is the following.
That is slash 24.
So apply this mask value on this input IP address you will get 92 .168.5.0.
Right.
And this entry do not matches this destination field of the routing table.
So simply this entry do not matches.
Right.
Similarly, this entry will also not match.
In fact, none of these entries will match.
Right.
Now for this entry, apply the mask value again to the input destination IP address.
Right.
So after applying the mask value slash 24 to the input destination IP address, you will get 92 .168.5.0.
So this is the entry of the routing table which matches.
Right.
So you can see that router knows that whenever it receives a packet with the destination.
IP address.
92.168 .5. ten.
It has to use this entry in the routing table.
And using this entry of the routing table, the router would know that it has to forward the packet
out of the local interface Ethernet three towards the next hop IP address.
192.168.1.2.
Right.
So now let us take another example.
Let us suppose that a router receives a packet whose destination IP address in the IP header is 122.1.1.
15.
Right now, if you apply again these four steps, you will find that first entry of the routing table
matches.
Right?
But also you will find that this entry of the routing table also matches.
Right.
How, for example, this entry has a mask value 16 So apply this 16 mask value on this destination IP
address you will get 122.1.0.0 which matches with the dest field of the routing table.
Right.
So you can see that for this IP address that is 122.1.1. 15.
There are two entries in the routing table which matches.
Right.
So what does the router have to do in this case?
Router cannot forwards the packet out of two local interfaces at the same time.
It has to forward the packet out of only one interface.
It means that the router has to choose one of these entries on some criteria in order to forward the
packet.
Right.
So that criteria is listed in point number three, that if two or more matching entries are found,
then one with the higher subnet mask is chosen.
So out of these two entries, you can see that its subnet mask value is 24, whereas its subnet mask
value is 16.
So the entry that is chosen to forward the packet will be the first entry.
So this is how we break the tie when there are multiple matching entries for a given destination IP
address.
So when the router receives a packet with destination IP address.
122.1.1. 15 it will use this entry and forwards the packet out of the local interface ethernet to towards
the next hop IP address.
100.1 68 .4.1.
So this concept of breaking the tie based on longest mask is called longest prefix match.
So this is the famous networking term and remember it is called longest prefix match.
Right.
So going forward now, let us suppose that the router had received a packet whose destination IP address
is 122.1.1. 15.
Right.
So the router performed the route lookup in its routing table.
And let us suppose that the first entry in the routing table matches.
So it means that the router has to forward the packet according to this entry.
So let us suppose that this root lookup is being happening on the router R1 so the router R1 knows that
it has to forward the packet out of local interface ethernet to.
Towards the next hope, whose IP address is 100.168 .4.1.
Right.
So it means that the router has to forward the packet in this direction.
So when the router r1 forwards the packet in this direction as per this routing table entry, what will
be the content of the Mac header and IP header in the packet?
So you can see that in Ethernet header, the destination Mac address will be B.
That is Mac address of the peer interface or the next hop interface and the source Mac address will
be the Mac address of the outgoing local interface.
So in this case the source Mac address will be Ma.
Right.
And in the IP header there are destination IP address and source IP address field.
So remember the content of destination IP address and source IP address fields in the IP header never
changes, so it will continue to be same.
Right.
We don't know where the packet was coming from.
So you can assume that the source IP address in the packet was 1.2.3.4.
That is anything.
So the point I'm trying to make here is that that when the router performs a route lookup, the router
will know that in which direction it has to forward the packet that is towards which router it has to
forward the packet and when the router forwards the packet, the content of ethernet header that is
the destination Mac address and source Mac address changes.
Whereas the content of IP header that is destination IP address and source IP address do not changes.
So this is how Layer three routing table is used by the layer three router, which helps the layer three
router to decide that where it has to forward the packet.
And the process of looking up a matching entry in the routing table is called route lookup.