Packet Forwarding in Routers

Avocado Aun
7 min readMay 26, 2020

There are more than one ways that leads to the destination

Intuition of Routing

The job of routers is to do routing. The end. If only routings were that simple. In this story, we will take a look at how routers actually do their job.

Now, imagine first time driving to a new mall. Intuitively, we use navigation apps like Google Maps or Apple Maps to point us to the right direction. Then we have this first world problems of which is the better route to take after we are offered several options.

Routing is similar to how we navigate in Google Maps

Funnily enough, router’s job scope is awfully similar to how we navigate in the real world. Routers too, have to know how to get to a destination network; and then to decide which is the best path to get there.

Packet Forwarding in Router

We know that routers are needed for packets to go from a local network to any remote networks. Routing is basically the process of forwarding a packet from a router’s entry interface out to an exit interface. Routing and forwarding is sometimes used interchangbly. So, how exactly does a router forwards packets?

Visualising the forwarding action in routers

Well — because router simply accepts an incoming packet on an interface; then send this packet out to another interface. Since a router can have multiple interfaces; it needs to intelligently choose an exit interface that can leads the packet to its intended destination. In the figure above, Router7 gets an packet on the left interface; and it ‘forwards’ this packet out to the right interface. Cool, but why not send this packet out to the middle interface?

Router made forwarding decision based on its routing table. The routing table contains entries of destination networks; and which exit interface to forward the packet to. This exit interface — is determined by many factors. First, it has to leads to the destination network. Second, it has to be the best path that leads to the destination network. All these information is stored in routers’ routing table.

Routing Table

Let’s take a deeper dive into the components inside a routing table. We can easily get the routing table on any routers using show ip route command.

The structure of a Routing Table

Codes

The code section indicates the types of routing for each routes. The code is abbreviated into C, R, S etc. We simply refers to the code table at the start of the routing table to corresponding routing types.

‘C’ is the most common tag; which indicate the directly connected networks. ‘C’ automatically appears on the routing table whenever a new network is added to it directly. No configurations are needed for ‘C’ networks. In our example, we imply that there are 2 networks directly connected to the this router.

‘S’ indicates static routing; ‘S’ appears when we configure static route to a destination network. ‘S’ also appears when we configure a default route on the router (default route is a type of static route). Here we imply that there is a static route leading to 192.168.3.0 network.

‘R’ indicates RIP protocol; which is a type of dynamic routing. In fact, all codes corresponds to dynamic routing except for ‘C’ and ‘S’. ‘R’ appears on the table when we configure RIPv1 or RIPv2 on the source router and also the destination router. ‘R’ does not appear if only one side is configured with RIP. Here, we imply that there is one dynamic route that leads to 192.168.2.0 network.

Destination Networks

As the name implies, the destination network component indicates the network address of the destination. It means the ‘network’ that we are trying to get to from this router. This is similar to the ‘destination’ we typed into Google maps for navigation.

Remember that every network has a network address, and packets are sent from one network to another based on this address (not host address). If the network address is not known but we have a host IP within that network; we need to calculate the network address by performing the ‘AND’ operation using the hostIP and the subnet mask of the network.

In our example, this router know its way to 4 different networks; namely, 192.168.1.0/24, 192.168.2.0/24, 192.168.3.0/24 and 200.1.1.0/24.

Admin Distance (AD)

This value indicates the precedence of the routes on a router. Suppose that we have two routes that leads to the same destination. Here, the router pick the route priority based on the AD value.

There are two parts in the AD values:

[Distance Value/Metrics]Example:
[120/1]

The distance value indicate the numerical ranking of routes from 0 to 255. The smaller the value, the more important a route is. For example, if routeA has AD=[1/0] and routeB has AD=[100/0] to the same destination; router will choose routeA due to its lower distance value (1 vs 100). Normally, a static route always has the default distance value of ‘1’; which means static routing always has higher precedence than dynamic routing. This means that if there is a static route and a dynamic route to the same destination, the dynamic route will never be used. Here’s the full table of default distance value in Cisco routers.

Default Distance Value

Every type of routes have their own default distance value. For example, if an OSPF route and a RIP route both goes to the same destination. The router will automatically choose OSPF due to its lower default distance value. To overwrite this, we can simply change the distance value of RIP to a value smaller than 110.

Note: the distance value can be changed by the network administrator to give different priority to different routing types.

The Metrics in the AD is used to indicate route preferences among routes of same types. If there are two RIPv1 routes that goes to the same destination. Here, the router will further decide which is the better RIPv1 route based on the Metric value. In RIPv1, the metric is hop count. The router will choose the RIPv1 route with the smaller hop count. For example, we have:

Route#1
========
R 192.168.1.0/24 [120/5]
Route#2
========
R 192.168.1./024 [120/2]

Here, router select Route#2 as the better route to forward network packets due to its lower hop count. The Metrics value are different for every protocols; for example, OSPF use link metric like speed or reliability instead of hop count.

Next Hop

This field indicates the IP address of the next hop router. Network packets are forwarded from one router to another en-route to the destination. The ‘hop’ here loosely refers to the routers along the transmission path. The next hop router is simply the next adjacent router that the local router will forward the packets to next.

For example, to send packets from LAN1 to LAN2; when the packet arrive at Router0, it will forwards this packet to Router1 (which is the next hop router). Here, the next hop IP is 200.1.1.2; which is the IP address of Router1’s outwards interface.

The Next Hop Router

Exit Interface

Remember router works by ‘receiving’ a packet from one interface and ‘forward’ this packet out to another interface. The interface that the packets are being forward out to; is called the Exit Interface. This is normally tagged as the interface names; for example, e0/0, fa0/0 or g0/0 depending on the interface types.

Packets entering a router from fa0/0 and going out from fa0/1 (this process is call forwarding)

In our example, PC0 sends a packet to PC2. When the packet arrived at Router0 from fa0/0; it will checks the exit interface that leads to LAN2. In this case, the exit interface is fa0/1. Router0 then forward the packets out from itself via fa0/1 interface.

Packets going IN and getting OUT from Router0 towards the destination

Fun Quiz: if PC0 sends a packet to PC1; do you think the packet will go INto fa0/0 of Router0; and exit from Router0 using the same fa0/0 interface?

Reading a routing table

Making sense of Router0 Routing Table

Now that we’ve learnt the components in the routing table; let’s examine what does Router0 table tells us.

First, we know that Router0 can go to 4 different networks (there are 4 destination networks)

Second, we know that two of these networks are directly connected (there are 2 ‘C’ in the table); which means only two routes are configured.

Third, we know that LAN1 can go to LAN3 through Router0 using a static route to the next hop router Router3 with the IP 200.1.1.3 (the route is tagged as ‘S’). This means, even if we configure dynamic route from LAN1 →LAN3; the static route will still be used.

Fourth, we know that LAN1 can go to LAN2 through Router0 using a RIPv1 route and the next hop router is Router1 with the IP 200.1.1.2 (this route is tagged as ‘R’)

Fifth, we know that there is a default route configured on Router0 pointing to Router3 (tagged as ‘S*’ in the table). Default route means the last resort of routing; which is the path a packet should travel if the router does not know where to forward it to. This means that Router0 will forwards any packets having destination network that is not in its router table to Router3.

--

--

Avocado Aun

I’m just a little boy, lost in the tech world. But remember, love is a riddle, and life with tech is more amazing than ever