CN-UNIT-3 - Network Layer

Download as pdf or txt
Download as pdf or txt
You are on page 1of 71

UNIT-3

Network Layer
B SAI BABA,M.Tech(Ph.D),VIT,Bhimavaram
B. SAI BABA,VIT,BVRM

Syllabus
★ Network Layer:
○ Network layer design issues
★ Routing Algorithms:
○ Optimality Principle
○ Shortest Path Algorithm
○ Flooding
○ Distance Vector
○ Link State Routing
○ Hierarchical Routing
○ Broadcast Routing
○ Multicast Routing
★ Congestion Control Algorithms
B. SAI BABA,VIT,BVRM

Network Layer Design Issues


B. SAI BABA,VIT,BVRM

★ The Network Layer or Layer 3 of the OSI (Open Systems Interconnection) model is

concerned delivery of data packets from the source to the destination across multiple hops or

links.

★ The design issues can be elaborated as−

1. Store − and − Forward Packet Switching

2. Services to Transport Layer

3. Providing Connection Oriented Service

4. Providing Connectionless Service

5. Routing

6. Congestion Control
B. SAI BABA,VIT,BVRM

Store − and − Forward Packet Switching


B. SAI BABA,VIT,BVRM

Store − and − Forward Packet Switching


★ The network layer operates in an environment that uses store and forward packet

switching.

★ The node which has a packet to send, delivers it to the nearest router.

★ The packet is stored in the router until it has fully arrived and its checksum is verified for

error detection.

★ Once, this is done, the packet is forwarded to the next router.

★ Since, each router needs to store the entire packet before it can forward it to the next hop,

the mechanism is called store − and − forward switching.


B. SAI BABA,VIT,BVRM

Services to Transport Layer


★ The Network Layer provides service to its immediate upper layer, namely Transport Layer,
through the network − transport layer interface.
★ The two types of services provided are −
1. Connection − Oriented Service :

In this service, a path is setup between the source and the destination, and all the
data packets belonging to a message are routed along this path.

2. Connectionless Service :

In this service, each packet of the message is considered as an independent entity


and is individually routed from the source to the destination.
B. SAI BABA,VIT,BVRM

Providing Connectionless Service


★ If connectionless service is offered, packets are injected into the network

individually and routed independently of each other.No advance setup is needed.

★ In this context, the packets are frequently called datagrams and the network is

called a datagram network.

★ In this section, we will examine datagram networks :


B. SAI BABA,VIT,BVRM
Figure 5-2. Routing within a datagram network
B. SAI BABA,VIT,BVRM

★ Let us assume for this example that the message is four times longer than the maximum packet
size, so the network layer has to break it into four packets, 1, 2, 3, and 4, and send each of
them in turn to router A using some point-to-point protocol.
★ At this point the ISP takes over. Every router has an internal table telling it where to send
packets for each of the possible destinations.
★ Each table entry is a pair consisting of a destination and the outgoing line to use for that
destination. Only directly connected lines can be used.
★ For example, in Fig. 5-2, A has only two outgoing lines—to B and to C—so every incoming
packet must be sent to one of these routers, even if the ultimate destination is to some other
router.
★ A’s initial routing table is shown in the figure under the label ‘‘initially.’’
B. SAI BABA,VIT,BVRM

★ At A, packets 1, 2, and 3 are stored briefly, having arrived on the incoming link and had their
checksums verified. Then each packet is forwarded according to A’s table, onto the outgoing
link to C within a new frame.
★ Packet 1 is then forwarded to E and then to F. When it gets to F, it is sent within a frame
over the LAN to H2. Packets 2 and 3 follow the same route.
★ However, something different happens to packet 4.
★ When it gets to A it is sent to router B, even though it is also destined for F.
★ For some reason, A decided to send packet 4 via a different route than that of the first three
packets. Perhaps it has learned of a traffic jam somewhere along the ACE path and updated
its routing table, as shown under the label ‘‘later.’’
★ The algorithm that manages the tables and makes the routing decisions is called the routing
algorithm.
B. SAI BABA,VIT,BVRM

Providing Connection Oriented Service

★ If connection-oriented service is used, a path from the source router all the way to the

destination router must be established before any data packets can be sent.

★ This connection is called a VC (virtual circuit),

★ The network is called a virtual-circuit network.


B. SAI BABA,VIT,BVRM
Figure 5-3. Routing within a virtual-circuit network
B. SAI BABA,VIT,BVRM

★ The idea behind virtual circuits is to avoid having to choose a new route for every packet
sent, as in Fig. 5-2.
★ Instead, when a connection is established,a route from the source machine to the destination
machine is chosen as part of the connection setup and stored in tables inside the routers.
★ That route is used for all traffic flowing over the connection, exactly the same way that the
telephone system works.
★ When the connection is released, the virtual circuit is also terminated.
★ With connection-oriented service, each packet carries an identifier telling which virtual
circuit it belongs to.
★ As an example, consider the situation shown in Fig. 5-3. Here, host H1 has established
connection 1 with host H2. This connection is remembered as the first entry in each of the
routing tables.
B. SAI BABA,VIT,BVRM

★ The first line of A’s table says that if a packet bearing connection identifier 1 comes in from
H1, it is to be sent to router C and given connection identifier 1.
★ Similarly, the first entry at C routes the packet to E, also with connection identifier 1.
★ Now let us consider what happens if H3 also wants to establish a connection to H2.
★ It chooses connection identifier 1 (because it is initiating the connection and this is it's only
connection) and tells the network to establish the virtual circuit.This leads to the second row in
the tables.
★ Note that we have a conflict here because although A can easily distinguish connection 1
packets from H1 from connection 1 packets from H3, C cannot do this. For this reason, A
assigns a different connection identifier to the outgoing traffic for the second connection.
★ Avoiding conflicts of this kind is why routers need the ability to replace connection identifiers
in outgoing packets. In some contexts, this process is called label switching.
B. SAI BABA,VIT,BVRM

Comparison of Virtual Circuit and Datagram Network


B. SAI BABA,VIT,BVRM
B. SAI BABA,VIT,BVRM

Routing Algorithms
B. SAI BABA,VIT,BVRM

Routing Algorithm

★ In order to transfer the packets from source to the destination, the network layer must
determine the best route through which packets can be transmitted.
★ Whether the network layer provides datagram service or virtual circuit service, the main
job of the network layer is to provide the best route. The routing protocol provides this job.
★ The routing protocol is a routing algorithm that provides the best path from the source to the
destination. The best path is the path that has the "least-cost path" from source to the
destination.
★ Routing is the process of forwarding the packets from source to the destination but the best
route to send the packets is determined by the routing algorithm.
B. SAI BABA,VIT,BVRM

Optimality Principle
B. SAI BABA,VIT,BVRM

Introduction :
★ A general statement is made about optimal routes without regard to network topology or
traffic. This statement is known as the optimality principle( Bellman,1975).
Statement of the optimality principle :
★ It states that if the router J is on the optimal path from router I to router K, then the optimal
path from J to K also falls along the same route. Call the route from I to J, r1 and the rest of
the route r2. it could be concatenated with r1 to improve the route from I to K, contradicting
our statement that r1r2 is optimal only if a route better than r2 existed from J to K.
B. SAI BABA,VIT,BVRM

Introduction :
★ A general statement is made about optimal routes without regard to network topology or
traffic. This statement is known as the optimality principle( Bellman,1975).
Explanation:
★ The purpose of a routing algorithm at a router is to decide which output line an incoming
packet should go.
★ The optimal path from a particular router to another may be the least cost path, the least
distance path, the least time path, the least hops path or a combination of any of the above.

The optimality principle can be logically proved as follows −


If the router J is on the optimal path from router I to router K, If a better route could be found
between router J and router K, the path from router I to router K via J would be updated via
this route. Thus, the optimal path from J to K will again lie on the optimal path from I to K.
B. SAI BABA,VIT,BVRM

Example
Consider a network of routers, {G, H, I, J, K, L, M, N} as shown in the figure. Let the
optimal route from I to K be as shown via the green path, i.e. via the route I-G-J-L-K.
According to the optimality principle, the optimal path from J to K with be along the
same route, i.e. J-L-K.
B. SAI BABA,VIT,BVRM

Now, suppose we find a better route from J to K is found, say along J-M-N-K.
Consequently, we will also need to update the optimal route from I to K as I-GJ- M-N-K,
since the previous route ceases to be optimal in this situation. This new optimal path is
shown line orange lines in the following figure −
B. SAI BABA,VIT,BVRM

Types of Routing Algorithm


B. SAI BABA,VIT,BVRM

Adaptive Routing Algorithm


★ Adaptive routing algorithm is also called a dynamic routing algorithm.

★ In this algorithm, the routing decisions are made based on network traffic and topology.

★ The parameters which are used in adaptive routing algorithms are distance, hop,

estimated transit time.

★ The adaptive routing algorithm is of three types –

○ Centralized algorithm

○ Isolation algorithm

○ Distributed algorithm
B. SAI BABA,VIT,BVRM

Centralized algorithm:
★ In centralized routing, one centralized node has the total network information and takes
the routing decisions.
★ It finds the least-cost path between source and destination nodes by using global
knowledge about the network. So, it is also known as global routing algorithm.
★ The advantage of this routing is that only the central node is required to store network
information and so the resource requirement of the other nodes may be less.
★ Eg: Link state routing algorithm
Isolated algorithm:
★ This algorithm procures the routing information by using local information instead of
gathering information from other nodes.
B. SAI BABA,VIT,BVRM

Distributed algorithm:
★ This is a decentralized algorithm where each node receives information from its
neighbouring nodes and takes the decision based upon the received information.
★ The least-cost path between source and destination is computed iteratively in a
distributed manner.
★ An advantage is that each node can dynamically change routing decisions based upon the
changes in the network.
★ Example : distance vector routing algorithm.
B. SAI BABA,VIT,BVRM

Non-adaptive Routing Algorithm


★ Non-adaptive routing algorithm is also called a static routing algorithm.

★ In a non-adaptive routing algorithm, the routing decisions are not made based on

network traffic and topology.

★ This algorithm is used by static routing.

★ Non-adaptive routing algorithms are simple as compared to Adaptive routing algorithms in

terms of complexity.

★ The non-adaptive routing algorithm is of two types –

○ Flooding

○ Random walks
B. SAI BABA,VIT,BVRM

Shortest Path Algorithm


B. SAI BABA,VIT,BVRM

Introduction:
★ Dijkstra's algorithm and the Bellman-Ford algorithm are two different algorithms used

to find the shortest path in a weighted graph.

Dijkstra's algorithm Bellman-Ford algorithm

It works only for graphs with It works for graphs with both
non-negative edge weights. non-negative and negative edge
weights.
B. SAI BABA,VIT,BVRM

Dijkstra's algorithm:

★ The shortest path algorithm was first introduced by Edsger W. Dijkstra in 1956.

★ This algorithm, commonly known as Dijkstra's algorithm, is used to find the shortest path

between nodes in a graph, particularly in weighted graphs where each edge has a

non-negative weight.

★ Dijkstra's algorithm is widely used in various applications, including computer

networking, transportation systems, and more, to find the shortest path from a source

node to all other nodes in the graph.


B. SAI BABA,VIT,BVRM

Procedure of Shortest Path Algorithm


★ Initially mark all nodes (except source) with infinite distance.
○ working node = source node
○ Sink node = destination node
★ While the working node is not equal to the sink
1. Mark the working node as permanent.
2. Examine all adjacent nodes in turn
○ If the sum of label on working node plus distance from working node to adjacent
node is less than current labeled distance on the adjacent node, this implies a shorter
path. Re label the distance on the adjacent node and label it with the node from which
the probe was made.
○ 3. Examine all tentative nodes (not just adjacent nodes) and mark the node with the
smallest labeled value as permanent. This node becomes the new working node.
★ Reconstruct the path backwards from sink to source
B. SAI BABA,VIT,BVRM

● The idea is to build a graph of the network, with each node of the graph representing a
router and each edge of the graph representing a communication line, or link.
● To choose a route between a given pair of routers, the algorithm just finds the shortest
path between them on the graph.
● The concept of a shortest path deserves some explanation.
○ One way of measuring path length is the number of hops. Using this metric, the paths
ABC and ABE in Fig. are equally long.
○ Another metric is the geographic distance in kilometers, in which case ABC is
clearly much longer than ABE
B. SAI BABA,VIT,BVRM
B. SAI BABA,VIT,BVRM

● The first six steps used in computing the shortest path from A to D.

● The arrows indicate the working node.


Example :2
B. SAI BABA,VIT,BVRM

Distance Vector Routing Algorithm

“Distant vector routing algorithm also called as Bellman-Ford algorithm or Ford


Fulkerson algorithm used to calculate the shortest path in the network.”
B. SAI BABA,VIT,BVRM
B. SAI BABA,VIT,BVRM

Asynchronous :An asynchronous algorithm is one in which nodes operate


independently and don't necessarily follow a synchronized clock or timing
B. SAI BABA,VIT,BVRM
Each router prepares its routing table. By their local knowledge. each router knows
about-
● All the routers present in the network
● Distance to its neighboring routers
B. SAI BABA,VIT,BVRM
B. SAI BABA,VIT,BVRM

Bellman-Ford algorithm:
The Distance Vector calculation is based on minimizing the cost to each
destination
Dx(y) = Estimate of least cost from x to y
C(x,v) = Node x knows cost to each neighbor v

Dx(y) = min { C(x,v) + Dv(y) }

Source Destination Intermediate Node


B. SAI BABA,VIT,BVRM

At Router A :
B. SAI BABA,VIT,BVRM

Updating “A Routing Table”


B. SAI BABA,VIT,BVRM

At Router B:
B. SAI BABA,VIT,BVRM

Updating “B Routing Table”


B. SAI BABA,VIT,BVRM

At Router C:
B. SAI BABA,VIT,BVRM

Updating “C Routing Table”


B. SAI BABA,VIT,BVRM

At Router D:
B. SAI BABA,VIT,BVRM

Updating “D Routing Table”


New Routing Tables:
B. SAI BABA,VIT,BVRM

Router A Router B

Router C Router D
B. SAI BABA,VIT,BVRM

"Still, the routing tables don't produce an optimal path.


So, repeat the process, i.e., each router exchanges its
tables until the table gives an optimal path."
B. SAI BABA,VIT,BVRM
At Router A-
● Router A receives distance vectors from its neighbors B and D.
● Router A prepares a new routing table as-

● Cost of reaching destination B from router A = min { 2+0 , 1+3 } = 2 via B.


● Cost of reaching destination C from router A = min { 2+3 , 1+10 } = 5 via B.
● Cost of reaching destination D from router A = min { 2+3 , 1+0 } = 1 via D.
B. SAI BABA,VIT,BVRM

The new routing table at Router A is-


B. SAI BABA,VIT,BVRM
At Router B-
● Router B receives distance vectors from its neighbors A, C and D.
● Router B prepares a new routing table as-

● Cost of reaching destination A from router B = min { 2+0 , 3+5 , 3+1 } = 2 via A.
● Cost of reaching destination C from router B = min { 2+5 , 3+0 , 3+10 } = 3 via C.
● Cost of reaching destination D from router B = min { 2+1 , 3+10 , 3+0 } = 3 via A.
B. SAI BABA,VIT,BVRM

The new routing table at Router B is-


B. SAI BABA,VIT,BVRM
At Router C-
● Router C receives distance vectors from its neighbors B and D.
● Router C prepares a new routing table as-

● Cost of reaching destination A from router C = min { 3+2 , 10+1 } = 5 via B.


● Cost of reaching destination B from router C = min { 3+0 , 10+3 } = 3 via B.
● Cost of reaching destination D from router C = min { 3+3 , 10+0 } = 6 via B.
B. SAI BABA,VIT,BVRM

The new routing table at Router C is-


B. SAI BABA,VIT,BVRM
At Router D-
● Router D receives distance vectors from its neighbors A, B and C.
● Router D prepares a new routing table as-

● Cost of reaching destination A from router D = min { 1+0 , 3+2 , 10+5 } = 1 via A.
● Cost of reaching destination B from router D = min { 1+2 , 3+0 , 10+3 } = 3 via A.
● Cost of reaching destination C from router D = min { 1+5 , 3+3 , 10+0 } = 6 via A.
B. SAI BABA,VIT,BVRM

The new routing table at Router D is-


These will be the final routing tables at each router.
B. SAI BABA,VIT,BVRM

Router A Router B

Router C Router D

You might also like