Network Layer in OSI Model
Network Layer in OSI Model
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
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
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
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
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
--->
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
---->
- 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
- Notation
x.y.z.w/n-------> n is the mask: no. of bits used to represent network ID (prefix length)
Ex. 200.45.67.23/21
***No. of hosts will always be 2 less than the total number of IP addresses since 1st and last IP
addresses aren’t used
Network Address : 1st IP address of the block —> Network ID + 0000… (host ID part is zero)
Broadcast address: last IP address of block
Step 4 No of IPs
47-32+1 = 16
Subnetting
Subnets, Subnet Mask, Routing | L3 | Computer Networks | GATE CS/IT #Ravindrababu…
If we divide a network into 2 in a network that has 24 bits taken by network ID…
Subnet Address : 1st IP address of subnet (basically Network address equivalent of subnet)
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.
________.________.________.__ ______
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.
Routing is making the decision which routes to use, and forwarding, which is what happens
when a packet arrives
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
- 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)
- 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
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
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
1 Routing based on neighbor's distance Routing based on linked state packets sent by
vectors every router
7 Less bandwidth since only distance More bandwidth since entire linked state
vectors exchanged packets exchanged
1 Finds the shortest distance between Finds distance of every node for every node
source and destination node in the network
4 Can’t work with negative weights Can work with negative weights