I am super excited to welcome you to my favorite aspect of networking — Routing. Together let’s explore the fascinating world of routing and understand what makes the Internet tick.
In this post, let’s get our feet wet in routing by understanding
- What is a router?
- What is routing and forwarding?
- Administrative Distance
- Dynamic Routing Protocols
We studied switching and understood how a Local Area Network (LAN) is realized. An obvious question might have popped up in your mind, how would those devices get out of their network and connect with devices in another network? Could there be a process by which different networks are seamlessly connected?
The answer to those question can be succinctly stated in a single word–Routing.
What is a Router ?
Router is a network device that interconnects different networks and forwards data packets between them. Whenever a device wants to reach a network or VLAN other than its own, it requires a Layer-3 device such as a router to forward the packets to other networks.
Router is a Layer-3 Device
Router operates at Layer-3 (Network) of the OSI Reference Model. Router is synonymous with Internet Protocol (IP). Router works with IP addresses whereas Switch MAC addresses. Router looks at the destination IP address of the packet to determine the path it should take. No IP address, no router.
Router is Realized in Software
Switches are realized in hardware by using ASICs (Application Specific Integrated Circuitry) which enable them to switch frames at wire speed. Routers on the other hand, don’t have ASICs and their functions are realized in software, because of which its processing is not as fast or efficient as that of switches.
Router has Limited Number of Ports
Switches are used to connect computers and other devices together. Consequently, they have more number of ports like 24 ports, 48 ports and even 128 ports. Routers on the other hand, are designed to connect networks, and the number of ports are typically 2 to 4. Of course, you can add interface modules to support more connections/networks.
Router is the Boundary of Networks
A router is a delineation between networks. Every arm of the router represents a different network. Contrasting that with a switch, all computers connected to a switch are essentially in one network.
What is Routing and Forwarding ?
The main purpose of a router is to connect multiple networks and forward packets destined either for its own networks or other networks. A router is considered a Layer 3 device because its primary forwarding decision is based on the information in the Layer 3 IP packet, specifically the destination IP address. This process is known as routing.
Consider the following network in which Network-1 (192.168.1.0/24) is connected to Network-2 (192.168.2.0/24) through the router R1. The router interface connecting to a network segment act as a gateway to another network segment — FastEthernet 0/0 is the gateway to Network-1 and FastEthernet 0/1 to Network-2.
Since the two networks are immediate to the router and are directly connected, the routes to these network are called directly connected routes. In a Cisco router, the routing table can be seen by running the show ip route command.
show ip route
Every route entry has five parts :
1. Code : This indicates how the route was learned. A route can be directly connected to the router (C) or statically assigned (‘S’), or learned from a dynamic routing protocol such as RIP (‘R’), EIGRP(‘D’), OSPF(‘O’), IS-IS(‘i’), or BGP(‘B’) etc.
2. Network : This is the network address the router knows how to reach.
3. AD/Metric tuple : AD stands for administrative distance indicating the precedence of the route and metric represents the cost of the route. For both AD and Metric, lower values have more significance.
3. Next Hop : This is the IP address of the next router’s interface which will lead to the network.
4. Time stamp : Time elapsed since the route was learned.
5. Interface ID : Local interface of the router on which the route was learned.
To better appreciate the routing process, consider the following slightly more complex network.
Here the three routers R1, R2, and R3 are interconnected through serial links with R1 and R2 serving routing for their respective LANs — 192.168.1.0/24, 192.168.2.0/24. The networks 10.1.2.0/30 between R1 and R2, 10.2.3.0/30 between R2 and R3 and 10.1.3.0/30 between R1 and R3 are typically WAN connections leased from the service provider.
Let’s study the routing table of R1:
R1#show ip route Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route Gateway of last resort is not set 10.0.0.0/30 is subnetted, 3 subnets C 10.1.3.0 is directly connected, Serial2/1 C 10.1.2.0 is directly connected, Serial2/0 D 10.2.3.0 [90/2681856] via 10.1.3.2, 00:15:52, Serial2/1 [90/2681856] via 10.1.2.2, 00:15:52, Serial2/0 D 192.168.1.0/24 [90/2172416] via 10.1.2.2, 00:15:51, Serial2/0 D 192.168.2.0/24 [90/2172416] via 10.1.3.2, 00:15:52, Serial2/1
R1 has learnt 5 routes. Two are directly connected networks — 10.1.3.0 and 10.1.2.0, indicated by the code ‘C’. The other three networks are learnt by the EIGRP routing protocol, indicated by the code ‘D’. The 10.2.3.0 network has two routes — one via R3(10.1.3.2) and the other via R2(10.1.2.2) which are learnt through the local interfaces Serial2/1 and Serial2/0 respectively. The router has two routes to the same network because both are equal cost(2172416) paths and are learnt from the same source EIGRP that has the Administrative distance of 90.
The LAN networks 192.168.1.0 and 192.168.2.0 are respectively learnt via R2(10.1.2.2) and R3(10.1.3.2).
Routers R2 and R3 have the similar routing table and can reach all the networks. With routers R1, R2 and R3 knowing all the networks, PCs don’t have any problem communicating with each other.
Forwarding is the process of moving packets from input to output. Functionally it’s similar to switching frames according to its CAM table. In a router, forwarding takes place based on the destination IP address of the packet. Router stores the best path to reach a network in its forwarding table known as Forwarding Information Base (FIB). Since router has to switch packets in the software, Cisco developed a more efficient way of forwarding the IP packets called CEF (Cisco Express Forwarding).
Routing is the process by which the forwarding table is built and maintained. The IP routing table likely to have more than one path to reach the destination (like we saw in our previous example). The IP routing table is populated with routes which may be directly connected routes, static routes or learned from a dynamic routing protocol. This table of all routes learned from many sources is called Routing Information Base (RIB). The RIB contains all the possible routes , whereas FIB the most suitable ones to reach a network.
Longest prefix match (also called Maximum prefix length match) refers to an algorithm used by routers to select an entry from a forwarding table.
For example, consider this IPv4 forwarding table:
When the address 192.168.20.19 needs to be looked up, both entries in the forwarding table “match”. That is, both entries contain the looked up address. In this case, the longest prefix of the candidate routes is 192.168.20.16/28, since its subnet mask (/28) is longer than the other entry’s mask (/16), making the route more specific.
Forwarding tables often contain a default route, which has the shortest possible prefix match, to fall back on in case matches with all other entries fail.
Also known as cost, metrics are used to determine whether one route should be chosen over another. The route with the lowest metric is chosen to forward the packet.
For example, RIP (Routing Information Protocol) uses hopcount (number of hops) to determine the best possible route. Router metrics can contain any number of values that help the router determine the best route among multiple routes to a destination. A router metric typically based on information like path length, bandwidth, load, hop count, path cost, delay, Maximum Transmission Unit (MTU), reliability and communications cost.
What if a route is learnt via multiple sources—say, via OSPF(Open Shortest Path First) and as a static entry? Each source of routing information has an attached measure of its trustworthiness, called administrative distance in Cisco parlance. The lower the administrative distance, the more trustworthy the source.
Thus, if a route is known both via OSPF and as a static entry, the static entry, not the entry known via OSPF, will be installed in the forwarding table.
Dynamic Routing Protocols
Dynamic routing protocols allow each router to automatically discover one or more paths to each destination in the network. When the network topology changes, such as when new paths are added or when paths go out of service, dynamic routing protocols automatically adjust the contents of the routing table to reflect the new network topology.
Dynamic routing relies on (frequent!) updates to discover changes in network topology. The routing protocols in use today are based on one of two algorithms: Distance Vector or Link State.
Distance Vector (DV) algorithms broadcast routing information to all neighboring routers. In other words, each router tells all of its neighbors the routes it knows. When a router receives a route (from a neighbor) that is not in its routing table, it adds the route to its table; if the router receives a route that is already in its routing table, it keeps the shorter route in its table. DV algorithms are sometimes also described as routing by rumor: bad routing information propagates just as quickly as good information.
Link State algorithms operate on a different paradigm. First, each router constructs its own topological map of the entire network, based on updates from neighbors. Next, each router uses Dijkstra’s algorithm to compute the shortest path to each destination in this graph.
A network under a single administrative authority is described as an autonomous system (AS) in routing parlance. Interior gateway protocols (IGPs) are designed to support the task of routing internal to an AS. IGPs have no concept of political boundaries between ASs or the metrics that may be used to select paths between ASs. RIP(Routing Information Protocol), IGRP (Interior Gateway Routing Protocol), EIGRP (Enhanced IGRP), and OSPF(Open Shortest Path First) are IGPs.
Exterior gateway protocols (EGPs) are designed to support routing between ASs. EGPs deploy metrics to select one inter-AS path over another. BGP is the most commonly used EGP.
Routing architectures may be broadly classified as flat or hierarchical. Flat routing
implies that all routes are known to all peers—all routers in the network are equal,
possessing the same routing information. Hierarchical routing implies that some
routers possess only local routes, whereas others possess a little bit more information, and still others possess even more.
In large IP networks, only a few routers need to know every route in the network.
These routers are sometimes described as core routers. Around the core routers is a
layer of distribution routers that need not possess the complete routing table. When a
distribution router receives a packet whose destination IP address does not appear in
its local routing table, the distribution router simply forwards the packet to a core
Some routing protocols have features that make it easier to build hierarchies. These features include route aggregation, classlessness, the use of default routes, and the flexibility with which routes can be exchanged with other routing protocols.
RIP is an example of an almost completely flat routing protocol. OSPF exhibits several features that permit the design of hierarchical networks.