You are on page 1of 22

Chapter 3

Network Layer

- The layer concerned with getting packets from source to destination through
intermediate routers
- responsible for the host-to-host delivery of datagrams.
- The lowest layer to deal with end-to-end transmission (datalink just deals with movement
of frames from an end of the wire to another)
- This layer also provides mechanisms for congestion control

Network Layer Design issues


1. Store and forward packet switching

H1 is a host that is like a home computer plugged onto ISP’s network routers. H2 is a
host on a LAN with a router F, owned and operated by a customer.
A host that needs to send a package sends it to the nearest router which stores it until
receiving it entirely, verifies the checksum and then passes it onto the next

2. Services provided to the transport layer


Goals of the network layer while providing services to the transport layer:
1. Services should be independent of router technology
2. The transport layer shouldn’t know the type, number and topology of the routers
in the network
3. Network addresses given to the network layers should be uniform
4. Should provide a connectionless service
Two factions have different opinions about what kind of services the network layer should
provide to the transport layer
- The internet community believes that it should provide connectionless service
- The telephone network community believes it should provide connection oriented service
since it is more reliable and provides better quality
As the internet progresses, it is also shifting to connection oriented with the rise of the demand
for quality.
3. Implementation of connectionless service
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
4. Implementation of connection-oriented service
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)

Types of Services provided to the transport layer

Connection less service (datagram network)


network layer treats each packet independently and it should carry source and destination
address
- the network is unreliable
- Error and flow control needed from host side
- Every packet may not follow the same path to destination
- The switches in this type of network are called routers which use only destination
address to route (no knowledge of previous packet)
- No advanced set-up needed
- Example: Internet Protocol (IP)

Working
If H1 wants to send a long message to H2 that is 4 times the size of the packet then the
message is sent as 4 packets. Packets 1,2,3, are sent to A and it stores them until 4 arrives (the
entire message needs to arrive before forwarding). It verifies the checksum and sends packets
forwards. 1,2,3 may take the same path but when 4 is being forwarded, A is told that there is a
traffic jam on the route so it sends packet 4 to a different route to reach F

Connection-Oriented service (virtual circuit network)


- Packets of the same message treated as a unit to avoid choosing a new route for every
packet sent
- After connection setup, the datagrams can all follow the same path
- Needed in connections where quality is important eg. phone call
- packet contains the source and destination addresses and a flow label (a virtual circuit
identifier that defines the virtual path the packet should follow)
- Phases:
1. Set-up
the source and destination addresses of the sender and receiver are used to
make table entries for the connection-oriented service
2. Data transfer
3. Tear Down
the source and destination inform the router to delete the corresponding entries.
- If a router crashes and loses its memory, all the virtual circuits passing through it will
have to be aborted.
- Ex: Multi-Protocol Label Switching (MPLS)

Working:
If H1 wants to send packets to H2, it establishes a connection and sends its packets with a
connection identifier. A’s table shows H1’s connection identifier number. If H3 also wants to
establish the connection it needs to have a unique identifier. It establishes a connection with
identifier 1 since it’s that host’s first connection but router A already has a connection 1 so it
switches the label of H3 packets to 2 while sending packets to the next routers.
Connectionless Vs Connection-Oriented Service
- Router memory Vs Bandwidth tradeoff
In VC, packets can travel with packet number and each packet wouldn’t have to store
destination address which saves memory
- Connection set-up time vs address parsing time
Depending on the network, it could either take longer to set up a VC or address parsing
at every node could be longer, depending on this we choose the type of service
- Connection oriented guarantees quality of service and flow control

Routers:

- When a packet arrives, its headers and trailers are stripped off and the payload field is
passed to the routing software which uses the header to choose the next router.
- Each table has an internal table mapping all the destinations the packet could be sent to,
this is called the routing table.
- Routing Algorithm: the algorithm that uses each routing table to make routing
decisions.
- Virtual circuit subnetting
In connection-oriented services, a connection called a virtual circuit is established before
packets are sent.
The subnet is called virtual circuit subnet
Services of network layer
- Routing
1. The layer chooses routes of communication lines making sure that none are
overloaded
2. Deals with problems when source and destination are in different networks
3. The routers in the path are not allowed to decapsulate the packets they received
unless the packets need to be fragmented.
4. The routers are not allowed to change source and destination addresses either
5. there is more than one route from the source to the destination. The network
layer is responsible for finding the best one with the help of routing protocols
- Forwarding
1. the action applied by each router when a packet arrives at one of its interfaces
using forwarding table
2. Router can forward to one connected network (unicast) or many (multicast)
depending on what the the packet header has

- Packetizing
1. encapsulating the payload (data received from upper layer) in a network-layer
packet at the source and decapsulating the payload from the network-layer
packet at the destination
2. the network layer accepts a packet from a transport layer, encapsulates the
packet in a datagram, and delivers the packet to the data-link layer
- Error control (header only)
1. Not a primary service since the packets can be fragmented at each router and
error checking would get less efficient
2. Hence, there is a checksum in just the header to prevent header corruption since
the main job of the router is to route not check the datagram

Network Layer Issues:


1. No flow control because
- There is hardly any error control so it’s job is easy and receiver will hardly get
overwhelmed
- Upper layers have buffers so receiver’s upper layer could implement those
- There is flow control in upper layers so having it in the network layer makes it
redundant
2. No congestion control
- Congestion happens when too many datagrams are present in one part of the
network causing some to drop.
- The dropping causes upper layers to request retransmission, causing more
congestion
3. Security
- The layer wasn’t designed keeping security in mind
- To provide security for a connectionless network layer, we need to have another
virtual level that changes the connectionless service to a connection-oriented
service

IPv4 Addressing
- A 32-bit address that uniquely and universally defines the connection of a host or a
router to the Internet.
- Connection less service
- The IP address is the address of the connection not the node, if the node is moved to
another network, IP address changes
- If a device has multiple connections to the internet, it has multiple IP addresses.
- The address is unique→ an address represents only one unique connection to the
internet
- The address is universal→ any device that wants to connect to the internet must accept
the addressing system

- Address Space:
The total number of addresses a protocol uses
The address space is 2^n= 2^32

- Notations
Binary IPv4 —> Dotted Decimal

--->

Divide into bits of 8 and convert each to decimal separated by dots

Rules:
- The dotted decimal can’t start from 0
- The value of each segment can’t be greater than 256
- There can’t be more that 4 segments (32 bits divided into 8 parts gives 4
segments)
- Mixture of binary and decimal digits not allowed

Dotted Decimal—> Binary IPv4

Replace each binary segment with its decimal equivalent

---->

- Hierarchy in addressing
A 32 bit IPv4 address is divided into two parts
1. Prefix (length=n): defines the network
2. Suffix (length=32-n): defines the node (connection of a device to the Internet)

Classful Addressing
- A hierarchy of division of IPv4 addresses in which the prefix length is fixed to
either 8 or 16 or 24 bits, dividing the types into 5 classes.

We took the 32 bits and fixed the first bit, dividing total IPs into 2.The first part was class
A…then we fixed the second bit of the second part again dividing into two. The first part was
class B and then we further divided by fixing the third bit…
No. of networks = 2^(no. Of prefix bits left after fixing) - 1
No. of IPs = 2^(no of suffix bits)

In class A, 1 bit is fixed to 0, remaining 7 bits are there hence no. of networks is (2^7)-1=127

In class B, 2 bits are fixed, remaining 6 are there from 1st byte and the whole second byte is
there hence no- of networks is 2^14 .

Class C

- Replaced by classless addressing cause a large part of the address space is


wasted
Each network assigned to Class A could hold 2^24 nodes (3 segments = 24 bits
left for suffix), which is too large for any single organization holding that single
network
Classless Addressing

- We don’t have classes, we have blocks.


- The prefix length is not fixed to define classes. User asks for X amt of IPs and prefix
length was defined accordingly

Divided into block/network ID and host ID

- Notation

x.y.z.w/n-------> n is the mask: no. of bits used to represent network ID (prefix length)

Out of the 32 bit n are used to represent prefix.

Ex. 200.45.67.23/21

No. of networks = 2^21 - 1


No of IPs = 2^11

***No. of hosts will always be 2 less than the total number of IP addresses since 1st and last IP
addresses aren’t used

No. of hosts = No. of IP addresses -2

Network Address : 1st IP address of the block —> Network ID + 0000… (host ID part is zero)
Broadcast address: last IP address of block

Q. A block is granted to an organization. 205.16.37.39/28 is one of the IP addresses.


Identify 1st and last IP of the block. Find the number of IPs.

Step 1 convert non mask part to binary

205.16.37.39 —> 11001101 00010000 00100101 00100111


Step 2
We know 28 bits are the network ID and 4 bits is the host ID. Starting of the 1st host ID will be
0000
11001101 00010000 00100101 00100000 is the first

Similarly 1111 will be last

<if mask is 21 then first will be 00000000000 (11 bits)>

Step 3 convert back to decimal


11001101 00010000 00100101 00100000→205.16.37.32

00010000 00100101 00101111→205.16.37. 47

Step 4 No of IPs

(Find 1st and last IP and subtract) +1

47-32+1 = 16
Subnetting
Subnets, Subnet Mask, Routing | L3 | Computer Networks | GATE CS/IT #Ravindrababu…

Dividing a big network into smaller networks

If we divide a network into 2 in a network that has 24 bits taken by network ID…

We fix 1 bit (either 0 or 1) that 1 fixed bit is subnet ID

Subnet Address : 1st IP address of subnet (basically Network address equivalent of subnet)

Similarly, when a network is divided into 4, we fix 2 bits (00,01,10,11)

If we have a network with its own network ID and broadcast ID and we subnet it to 2
subnetworks, the network ID of 1st is the same as the network ID of the entire network and the
broadcast ID of the second is the same as the broadcast ID of the entire network.

If a packet arrives from outside the network with 1st network ID then it will be broadcasted to the
entire network. If packet arrives from within the network with 1st network ID then it broadcasts to
1st subnet

In a divided network, the network address and broadcast address can’t be used by hosts even
in subnets therefore if a network is divided into 2, 4 can’t be used (network address of 1st which
is also the network address of entire network, broadcast address of 1st, network address of 2nd
and broadcast address of second which is also the broadcast address of entire network)
Subnet mask
A 32 bit number in which the number of 1s represent the network address and subnet address
and number of 0s represent the host address.

Ex. A network with 24 bits taken as network ID, we divide into 4 parts.

________.________.________.__ ______

1st 24 will be network ID = all 1


Next 2 bits are fixed to divide network into 4 subnets = both 1
Last 6 bits = host ID = 0

Subnet mask : 11111111.11111111.11111111.11 000000 = 256.256.256.192

When we add a subnet mask to any IP address in binary, we get the network ID to which the IP
address belongs. (bitwise add, so no carries). Router uses subnet mask to decide which subnet
to forward a packet to
Routing Algorithms
Routing algorithm is the part of network layer software that is responsible for deciding which
output line an incoming packet should be transmitted on.

The algorithm that manages the tables and makes the routing decisions is called the routing
algorithm.

Two processes of a router


1. Forwarding : looking up each output line for an incoming packet to enter into the routing
table
2. Routing: filing and updating routing tables using a routing algorithm

Routing is making the decision which routes to use, and forwarding, which is what happens
when a packet arrives

Desirable properties in a routing algorithm:


1. Correctness & simplicity
2. Robustness:
The algorithm should be able to account for changes in topology without halting the
processes in the router or rebooting in case of crash
3. Stability
Reaches equilibrium state fast and stays there
4. Fairness & optimality
5. Realizing and using sink trees based on optimality principle

Session Routing
If the network uses virtual circuits internally, routing decisions are made only when a new virtual
circuit is being set up. Thereafter, data packets just follow the already established route
Optimality Principle

Sink tree
- Tree formed by joining all the optimal paths of a node with other nodes
- a sink tree is a minimal cost tree formed with the given node as the destination and all
other nodes as sources
- The goal of routing algorithms is to find the sink tree for every node
- there can exist more than one sink tree having the same path length.
- There can’t be any loops in a sink tree
- They assume that paths don’t interfere with each other.
- As per a sink three, each packet will be delivered in finite hops
- This is the benchmark against which all other algorithms are measured

Types of Routing Algorithms

Non Adaptive (Static Routing)

- do not base their routing decisions on any measurements or estimates of the current
topology and traffic.
- Path is already computed and downloaded to the routers when they’re booted
- It is used when the routing choice is obvious
Adaptive routing (Dynamic Routing)
- Changes with change in topology and traffic
- They change:
1. When they receive new info from adjacent routers
2. When routes change (eg. topology changes)
3. When we change the metric of optimization (distance, number of hops, transit
time)

Shortest Path Algorithm (Eg: Djikstra’s)

- The algorithm constructs a graph for the subnet with each node representing a router
and each edge (arc) representing the link between routers.
- The labels on the arcs could be computed as a function of the distance, bandwidth,
average traffic, communication cost, mean queue length, measured delay,and other
factors
- finds the shortest paths between a source and all destinations in the network
- Working:
1. Every node is labeled with the shortest known path from the source and node
from which the probe was made. Initially no paths are known and no probes are
made so all nodes are marked (∞,-).
2. Labels of nodes can be tentative or permanent. Initially all labels are tentative.
When it’s found out that the label represents the shortest path from the source for
that node, it’s made permanent.
- It is a greedy algorithm i.e it chooses the best option for the given time without worrying
about the future
- Pros:
1. Low complexity, almost linear
2. Ideal for real life applications like maps
3. Works for both directed and undirected graphs
4. Can work for multiple costs for a given node
- Cons:
1. Can’t be used for negative weights
2. It does a blind search to find neighboring nodes, which is wasteful

–Refer to handwritten notes for questions–

Flooding
- Static routing algorithm
- Every incoming packet is sent out to every outgoing link except the one it arrived on
- This method generates infinite duplicates of the same packet unless some measures for
damming are taken
- Damming Measures:
1. Hop counter:
A counter in the packet header initialized to the length of the path from source to
destination. At every hop, it is decremented and the packet is discarded when it
reaches 0.
2. Selective Flooding:
Every incoming packet is not sent to every outgoing link, only the links that are
approx in the right direction
3. Routers keep track of which packets have been flooded, to avoid sending them
out a second time.
- Pros
1. ensures that a packet is delivered to every node in the network.
2. Robust
Even if a large number of routers are down, the message is sent to remaining
routers
3. requires little setup
4. No knowledge of network needed, routers only need to know their neighbours
5. no other algorithm can produce a shorter delay
6. Ideal for broadcasting
- Cons
1. Large overhead
2. Generates multiple copies of the same packet
3. Not secure
4. Network can clog due to the unnecessary copies of packets

Distance Vector Routing (Bellman-Ford Algorithm)


- Dynamic algorithm (changes with change in network topology)
- Each router maintains a routing table containing an estimate of distance from a given
node to every node of the network. Every entry has the node, its estimated distance and
the next hop that the packet needs to take to go to that node (first node of preferred
outgoing line).
- Tables update by sharing distance vectors to their neighbors
- No. of passes (sharing of vectors)= No of nodes - 1
- Pros:
1. Can work with negative weights
2. Simpler than link state
3. Negligible bandwidth requirement
4. Uses shortest path as primary criteria, hence efficient
- cons :
1. Slower to converge (reach a stable state)
2. Can have count to infinity problem (--Refer to handwritten notes–)
The problem arises when a node X tells Y the estimate of distance to another
node but Y has no way of knowing that X’s path contains Y or not.
It reacts rapidly to good news, but leisurely to bad news
3. Each router needs to know about every other router
4. Routers need to recalculate routing table before sending every packet
5. Not scalable. Larger network implies larger distance vector being shared

–Refer to handwritten nodes for questions–

Link State Routing


- Dynamic routing algorithm
- Each router must do the following
1. Discover its neighbors and learn their network addresses.
- Every node sends a ‘hello message’ to immediate neighbors and the
neighbors respond by sending their name and network address.
- If nodes are in a LAN, then it is better to consider the LAN as a node
2. Set the distance or cost metric to each of its neighbors.
- A common choice is to make the cost inversely proportional to the
bandwidth of the link so high bandwidth networks are preferred
- If the network is geographically spread out, the delay of the links may be
factored into the cost so that paths over shorter links are better choices
3. Construct a packet telling all it has just learned

The packet contains:


- Identity of sender
- Sequence number
1. To keep the flood in check, each packet contains a sequence
number that is incremented for each new packet sent by the node
2. When a router receives a packet from another node with an
increment sequence number, it forwards the packet, else it
ignores. Similarly if a packet with a lower sequence number
arrives, it’s discarded
3. A 32 bit sequence number is used to avoid repetition (wrap
around)
- Time to live (age)
1. If a router crashes, the next packet it sends to all will have
sequence number 0, hence all other routers will reject it. A
sequence number may also be corrupted when received, hence
we need the age of the router.
2. The age field is used to bound the maximum lifetime of a link state
packet (LSP) in the network. When a router generates a LSP, it
sets its lifetime (usually measured in seconds) in the age field. All
routers regularly decrement the age of the LSPs in their DB and a
LSP is discarded once its age reaches 0
- Neighbors and their cost
4. Send this packet to and receive packets from all other routers by flooding.
Packets can be sent:
- Periodically (rarely needed)
- When changes in topology occur

5. Compute the shortest path to every other router using dijkstra's algorithm .
Once a router has accumulated a full set of link state packets, it can construct the
entire network graph because every link is represented.

- Pros:
1. Fast convergence
2. Each router can separately determine the shortest path to every network.
3. Can manage large networks
4. Based on global knowledge of network
5. Periodic updates not needed, packets can be sent when topology changes with
info about the affected link (event driven updates)
- Cons:
1. Memory requirements
Each node maintains a database of packets to oversee flooding which can
require a huge amount of memory especially if the network is large
2. Bandwidth Requirements
Requires bandwidth since packets are sent, not just vectors
3. Computation requirements
Each node calculates the shortest path to every other node using dijkstra which
requires computation capabilities

Distance Vector Linked State

1 Routing based on neighbor's distance Routing based on linked state packets sent by
vectors every router

2 Based on local knowledge Based on global knowledge (entire network)

3 Uses Bellman-Ford Algorithm Uses Djikstra’s algorithm


4 Slow Convergence Fast Convergence

5 Can have count-to-infinity problem Can’t have count to infinity problem

6 Less traffic since no flooding More traffic

7 Less bandwidth since only distance More bandwidth since entire linked state
vectors exchanged packets exchanged

Shortest Path Algorithm Distance-Vector Algorithm

1 Finds the shortest distance between Finds distance of every node for every node
source and destination node in the network

2 Uses dijkstra algorithm Uses bellman ford algorithm

3 Static routing Dynamic routing

4 Can’t work with negative weights Can work with negative weights

5 Greedy algorithm Not a greedy algorithm

Problems with routing algorithms


- Distance vector and linked state rely on routers to make calculations to find shortest
routes. Problem in hardware and software of even one router may cause problems
- if a router claims to have a link it does not have or forgets a link it does have, the
network graph will be incorrect
- If a router fails to forward packets or corrupts them while forwarding them, the route will
not work as expected.
- if router runs out of memory or does the routing calculation wrong, problems arise

You might also like