Module-3 Network Layer
Module-3 Network Layer
MODULE 3
THE NETWORK LAYER
Introductions
The network layer is responsible for ensuring packets travel from the source to the destination.
This often involves multiple hops through intermediate routers. Therefore, the network layer
handles end-to-end transmission.
To accomplish its tasks, the network layer must understand the network's topology, select
appropriate paths, and manage traffic to prevent congestion. It also addresses challenges when the
source and destination are in different networks. In this chapter, with a primary focus on the
Internet and its network layer protocol, IP.
When a host has a packet to send, it sends it to the nearest router, either on its own LAN or via a
point-to-point link to the ISP. The router stores the packet until it's fully received and processed
(including checksum verification), after which it forwards the packet to the next router along the
path. This process continues until the packet reaches its destination host, where it is delivered. This
mechanism is known as store-and-forward packet switching.
1
Computer Networks
In a datagram network, let's consider the process of transmitting a long message from process P1
on host H1 to process P2 on host H2. Here's how it works:
1. Process P1 hands the message to the transport layer, which adds a transport header to the
message. This transport layer code runs on H1.
2
Computer Networks
2. The resulting data is then passed to the network layer, typically another procedure within
the operating system.
3. Since the message is longer than the maximum packet size, it's divided into four packets:
1, 2, 3, and 4. Each packet is sent one after the other to router A using a point-to-point
protocol like PPP.
4. Within the ISP's network, each router has a routing table indicating where to send packets
for each possible destination. These tables contain pairs of destinations and the outgoing
lines to use.
5. Router A initially has a routing table as shown in the figure. Packets 1, 2, and 3 are briefly
stored and checked for checksum on arrival. Then they are forwarded according to A's
table, reaching H2 via routers E and F.
6. However, something different happens to packet 4. Router A sends it to router B instead of
following the same route as the first three packets. This change in routing might occur if A
learns of a traffic jam along the initial route and updates its routing table.
7. The algorithm responsible for managing routing tables and making routing decisions is
called the routing algorithm, a central topic in this chapter. Different types of routing
algorithms exist.
8. IP (Internet Protocol), the foundation of the Internet, is a prime example of a connectionless
network service. Each packet carries a destination IP address, allowing routers to forward
packets individually. IPv4 packets have 32-bit addresses, while IPv6 packets have 128-bit
addresses.
3
Computer Networks
1. Instead of choosing a new route for every packet as in connectionless service, a route from
the source to the destination is selected and stored in tables within the routers when a
connection is established. This chosen route is then used for all data traffic over that
connection, similar to how the telephone system operates.
2. When the connection is terminated, the virtual circuit is also released. Each packet in a
connection-oriented service carries an identifier indicating which virtual circuit it belongs
to.
3. For example, if host H1 establishes connection 1 with host H2, this connection is recorded
as the first entry in the routing tables of each router along the route. Packets from H1 to H2
are then directed through this established route.
4. If another host, say H3, wants to establish a connection to H2, it chooses connection
identifier 1 and requests the network to establish a new virtual circuit. This leads to the
creation of a second entry in the routing tables.
5. To avoid conflicts, routers need the ability to replace connection identifiers in outgoing
packets. This process is sometimes called label switching. An example of a connection-
oriented network service is MPLS (Multi-Protocol Label Switching), used within ISP
networks. MPLS uses a 20-bit connection identifier or label to route traffic efficiently.
6. MPLS is often employed within ISP networks to establish long-term connections for large
traffic volumes. It helps ensure quality of service and assists with various traffic
management tasks, even though it's often transparent to customers.
4
Computer Networks
Inside a network, there are trade-offs between virtual circuits and datagrams:
5
Computer Networks
• For transaction processing systems, setting up and clearing virtual circuits may be
too costly compared to their use. However, for long-running applications like
VPNs, permanent virtual circuits can be valuable.
6. Vulnerability:
• Virtual circuits are vulnerable to disruptions if a router crashes and loses memory,
requiring all circuits to be aborted. Datagram networks are more resilient in this
regard.
7. Network Load Balancing:
• Datagram networks allow routers to balance traffic by changing routes during a
sequence of packet transmissions, providing flexibility compared to fixed virtual
circuits.
• Routing Algorithm: It decides which output line an incoming packet should be sent on. For
datagram networks, this decision is made for every data packet, while virtual-circuit networks
determine routes during setup and reuse them. This process can be divided into routing (route
selection) and forwarding (packet arrival handling).
• Desirable Properties: Routing algorithms should be correct, simple, robust (able to handle
failures and topology changes), stable (converging to fixed paths), fair, and efficient.
• Trade-offs: Efficiency and fairness can sometimes conflict in routing decisions, requiring a
balance. Networks often optimize goals like minimizing packet delay, maximizing total
throughput, or reducing the number of hops a packet travels.
• Routing Algorithm Classes: Routing algorithms are categorized as nonadaptive (pre-
computed routes) and adaptive (responding to changes in topology and traffic). Adaptive
algorithms can differ in information sources, frequency of route changes, and optimization
metrics.
6
Computer Networks
• Sink Tree: The sink tree is a tree-like structure formed by optimal routes from all sources
to a specific destination, adhering to the optimality principle. Sink trees play a central role
in routing algorithms, helping efficiently route packets in networks fig(b).
• Directed Acyclic Graphs (DAGs): Sink trees can extend to become DAGs if all possible
paths are considered, allowing for more flexibility in route selection. However, the
fundamental structure of a sink tree is retained in DAGs.
• Network Dynamics: In practice, network dynamics, such as link and router failures, can
affect the stability and accuracy of sink trees. Routers may have varying views of the
current topology, leading to dynamic adjustments in the sink tree.
Several algorithms are available for calculating the shortest path between two nodes in a graph.
The one we'll discuss is attributed to Dijkstra (1959) and is utilized to find the shortest paths from
a source to all destinations within the network. Each node is assigned a label (in parentheses)
indicating its distance from the source node along the best-known path. Distances must always be
non-negative, particularly when they are based on real factors like bandwidth and delay.
Initially, no paths are known, so all nodes are labeled with infinity. As the algorithm progresses
and identifies paths, labels may change to reflect better routes. Labels can be either tentative or
permanent, with all labels beginning as tentative. Once it's determined that a label represents the
shortest possible path from the source to a particular node, it becomes permanent and remains
unchanged thereafter.
In this algorithm illustration, we'll demonstrate the process using a weighted, undirected graph
(Fig. 5-7a), where the weights represent parameters like distance. Our objective is to discover the
shortest path from A to D. Here's how it works:
1. We begin by marking node A as permanent (indicated by a filled-in circle).
2. Next, we examine each node adjacent to A, one by one (the working node). We relabel each
of these nodes with the distance to A. Additionally, we record the node from which the
probe was made to reconstruct the final path later. If multiple shortest paths exist from A
to D, we must remember all the probe nodes that could reach a node with the same distance.
8
Computer Networks
3. Having examined all nodes adjacent to A, we then inspect all tentatively labeled nodes
across the entire graph. We make the one with the smallest label permanent (as shown in
Fig. 5-7b), and this node becomes the new working node.
4. We repeat the process, starting from node B and examining all nodes adjacent to it. If the
sum of the label on B and the distance from B to the considered node is less than the label
on that node, we have a shorter path, so the node is relabeled.
5. After inspecting all nodes adjacent to the working node and updating tentative labels if
necessary, we search the entire graph for the tentatively labeled node with the smallest
value. This node becomes permanent and serves as the working node for the next round.
Fig. 5-7 illustrates the first six steps of the algorithm.
To understand why this algorithm works, consider Fig. 5-7c. At this point, we've made E
permanent. Now, suppose there were a shorter path than ABE, let's say AXYZE (with X and Y as
intermediate nodes). There are two possibilities: Either node Z has already been made permanent,
or it hasn't. If it has, then E has already been probed in a previous round when Z became permanent,
so the AXYZE path has been considered, and it cannot be shorter.
Now, let's look at the case where Z is still tentatively labeled. If the label at Z is greater than or
equal to that at E, then the AXYZE path cannot be shorter than ABE. If the label is less than that
of E, then Z will become permanent before E, allowing E to be probed from Z.
3. Flooding
Routing algorithms often rely on local knowledge rather than a complete network view. One basic
local technique is "flooding," where every incoming packet is sent out on all outgoing lines except
the one it arrived on.
To control the potential chaos of flooding, a hop counter is added to each packet's header,
decrementing with each hop until the packet is discarded when the counter hits zero. Ideally, the
hop counter should be initialized to the estimated path length from source to destination.
To further manage flooding, routers keep track of flooded packets to avoid duplication. This can
be achieved by having source routers include sequence numbers in their packets and maintaining
lists of seen sequence numbers for each source.
While not practical for most packets, flooding has its uses. It ensures delivery to every node in the
network, making it useful for broadcasting information and maintaining robustness, even in
challenging conditions. Flooding's minimal setup requirements also make it a foundational element
for more efficient routing algorithms and a valuable metric for performance comparisons. Flooding
inherently chooses the shortest path, as it explores all possible paths simultaneously.
4. Distance Vector Routing
Distance Vector Routing is a common dynamic routing algorithm used in computer networks. It
operates by having each router maintain a table, known as a vector, which contains information
about the best-known distance to each destination and the appropriate link to reach it. These tables
9
Computer Networks
are continually updated through communication with neighboring routers, allowing each router to
determine the optimal path to every destination.
In distance vector routing, each router's routing table includes entries for every router in the
network. Each entry consists of the preferred outgoing line for that destination and an estimate of
the distance to reach it. The distance can be measured in various ways, such as the number of hops
or other metrics like propagation delay, which can be determined using specialized ECHO packets.
For instance, let's consider using delay as a metric, and assume that each router knows the delay
to its neighboring routers. Periodically, let's say every T milliseconds, each router shares a list of
its estimated delays to reach various destinations with its neighbors. In return, it receives similar
lists from its neighbors.
For instance, if a router receives a table from neighbor X with Xi representing X's delay estimates
to different routers, and it already knows the delay to X is m milliseconds, it can calculate that it
can reach router i via X in Xi + m milliseconds. By performing this calculation for each neighbor's
estimates, the router can determine the best estimate and corresponding link to update its routing
table. Notably, the old routing table is not used in this calculation.
This updating process is demonstrated in Figure 5-9. Part (a) depicts a network, and part (b)
illustrates delay vectors received from router J's neighbors. Each neighbor claims different delay
values to various destinations. Assuming J has its own delay estimates to its neighbors A, I, H, and
K as 8, 10, 12, and 6 milliseconds, respectively, it calculates its new route to router G. For example,
J knows it can reach A in 8 milliseconds, and A claims a 18-millisecond delay to G. Thus, J can
10
Computer Networks
Now consider the scenario in Fig. 5-10(b), where all links and routers are initially operational.
Routers B, C, D, and E have distances to A of 1, 2, 3, and 4 hops, respectively. Suddenly, either A
goes down or the A-B link is severed (effectively the same from B's perspective).
In the first exchange, B doesn't receive any news from A. Fortunately, C reports having a 2-hop
path to A. However, B doesn't know that C's path includes itself, so it believes the path to A via C
is 3 hops long. D and E don't update their entries for A in the first exchange.
In the second exchange, C realizes that its neighbors all claim to have 3-hop paths to A, so it
randomly picks one and updates its distance to A as 4 hops. Subsequent exchanges follow the
history shown in the figure.
This scenario illustrates why bad news travels slowly: no router's value exceeds the minimum of
its neighbors' values by more than one. Gradually, all routers increase their distance to infinity, but
the number of exchanges required depends on the value set for infinity. Therefore, setting infinity
to the longest path plus 1 is a prudent choice.
11
Computer Networks
This problem is known as the count-to-infinity problem, and various attempts have been made to
solve it, like using heuristics such as the split horizon with poisoned reverse rule discussed in RFC
1058. However, none of these heuristics work well in practice due to the fundamental challenge:
routers can't determine if they are on a path when another router advertises it.
5. Link State Routing
Link State Routing replaced Distance Vector Routing in the ARPANET in 1979 due to the count-
to-infinity problem, which caused slow convergence after network topology changes. This
innovative algorithm, now known as Link State Routing, forms the basis for widely used routing
protocols like IS-IS and OSPF. The Link State Routing concept comprises five key steps for routers
to function effectively:
1. Neighbor Discovery: Routers identify their neighboring devices and learn their network
addresses.
2. Distance Metric Assignment: Each router assigns distance or cost metrics to its
neighboring routers.
3. Packet Construction: Routers construct packets containing the information they've
gathered.
4. Packet Exchange: These packets are sent to and received from all other routers in the
network.
5. Shortest Path Computation: Routers calculate the shortest path to reach every other
router in the network.
Learning about the Neighbors: When a router boots up, it identifies its neighbors by sending
HELLO packets over point-to-point connections, receiving replies with unique neighbor names.
For broadcast links (e.g., Ethernet), the setup is more complex. Instead of modeling each link
separately, a LAN is treated as a single node. This node, with a designated router, connects routers
like A, C, and F. This simplifies the topology and reduces message overhead. Connectivity between
routers, like A and C, is represented as paths within this LAN node, such as ANC.
Setting Link Costs: In the link state routing algorithm, each link must have a distance or cost
metric for calculating the shortest paths. These metrics can be automatically determined or
configured by the network operator. Typically, cost is inversely proportional to link bandwidth,
making higher-capacity links preferable. For geographically dispersed networks, link delay can be
12
Computer Networks
factored into the cost, measured using Round-Trip Time with special ECHO packets, ensuring
shorter links are favored in path selection.
Building Link State Packets: In the link state routing algorithm, each router creates a packet
containing sender identity, sequence number, age, and neighbor list with associated costs. Packet
creation is straightforward. The challenge lies in determining when to build these packets. They
can be generated periodically or triggered by significant events like a line or neighbor status change
in fig 5.11.
Distributing the Link State Packets: Distributing link state packets is a crucial aspect of the
algorithm. To ensure all routers quickly and reliably receive these packets, a flooding approach is
used. Each packet contains a sequence number that is incremented with each new transmission,
preventing duplicates. However, to address potential issues, packet age is also included and
decremented periodically. Once the age reaches zero, the information is discarded. This technique
ensures timely updates and prevents obsolete data. Additionally, some refinements include a
holding area for incoming packets and the comparison of sequence numbers to handle duplicates
and errors, with all link state packets acknowledged to enhance robustness.
• Router B uses a data structure, as shown in Fig. 5-13, to manage link state packets. Each
row in this structure represents an incoming packet with information about its origin,
sequence number, age, and data. It also includes flags for sending and acknowledging
packets on B's three links (to A, C, and F).
• For example, when a packet arrives directly from A, it's sent to C and F and acknowledged
to A as indicated by the flag bits. Similarly, a packet from F is forwarded to A and C and
acknowledged to F.
• However, if a packet, like the one from E, arrives through multiple paths (EAB and EFB),
it's sent only to C but acknowledged to both A and F, reflecting the bit settings.
• In cases of duplicate packets arriving while the original is still in the buffer, the flag bits
are adjusted. For instance, if a copy of C's state arrives from F before the original is
forwarded, the bits are changed to indicate acknowledgment to F but no sending.
13
Computer Networks
Computing the New Routes: In link state routing, once a router has collected all link state packets
representing the entire network graph, it can construct a comprehensive view of the network,
considering links in both directions with potential different costs. Dijkstra's algorithm is then
employed locally to compute the shortest paths to all destinations, informing the router of the
preferred link for each destination, which is added to the routing tables.
Compared to distance vector routing, link state routing demands more memory and computation,
with memory needs proportional to k*n (n = number of routers, k = average neighbors), potentially
exceeding the size of a routing table. However, link state routing offers faster convergence, making
it practical for many scenarios. Actual networks often use link state routing protocols like IS-IS
(Intermediate System-Intermediate System) and OSPF (Open Shortest Path First).
14