Network Layer PDF
Network Layer PDF
Step 4
we don't have any tentative nodes, so we So the best route is ABDE. In this case, the total weigh is 4 (1+2+1).
just identify the next T-node. Since E has
the least weight, it has been chosen as T-
node
Shortest Path Routing Example
FLOODING
• Routing decision will be made based on the local knowledge, not on the complete
topology of the network.
• Every incoming packet is sent out on every outgoing line except the one it arrived on.
• Generates huge numbers of duplicate packets.
• Header of each packet will have a hop counter that is decremented at each hop, with
the packet being discarded when the counter reaches zero.
• Ideally, the hop counter should be initialized to the length of the path from source to
destination. If the sender does not know how long the path is, it can initialize the
counter to the worst case, with the full diameter of the network, but still flooding
generates duplicate packets..
• For avoiding the flood the better way is to have sources router to put sequence
number and the flooding routers keep track of which packets have been flooded, to
avoid sending them out a second time.
Dynamic Routing Algorithms
• Dynamic routing algorithms are more complex, but more efficient because they find
shortest paths for the current topology.
• The popular dynamic algorithms are Distance Vector Routing and Link State Routing.
• DVR maintains a table (i.e., a vector) at every router with two parts: preferred outgoing
line for destination and an estimate of the distance to that destination.
A 0 A A 2 A
B 2 B B 0 B
C ∞ – C 3 C
D 1 D D 7 D
Routing table of A Routing table of B
A ∞ – A 1 A
B 3 B B 7 B
C 0 C C 11 C
D 11 D D 0 D
Routing table of C Routing table of D
Distance Vector Routing Example
Step-02:
•Each router exchanges its distance vector obtained in Step-01 with its neighbors.
•After exchanging the distance vectors, each router prepares a new routing table.
Cost(src,dst)=min{cost(src, adjc-1)+(adjc-1, dst), cost(src, adjc-2)+(adjc-2, dest), cost(src, adjc-N)+ adjc-N, dest) }
A 0 A
B 2 B
@router A:
C 5 B
Router A receives distance vectors from its neighbors B and D.
Router A prepares a new routing table as- D 1 D
Distance Vector Routing Example
@router B:
Router B receives distance vectors from its neighbors A, C and D.
A 2 A
B 0 B
C 3 C
D 3 A
@router C:
A 5 B
B 3 B
C 0 C
D 10 B
Distance Vector Routing Example
@router D:
Router D receives distance vectors from its neighbors A, B and C.
A 1 A
B 3 A
C 10 B
D 0 D
Distance Vector Routing Example
Step-03:
Each router exchanges its distance vector obtained in Step-02 with its neighboring routers.
After exchanging the distance vectors, each router prepares a new routing table.
Destin Dista Next
@ Router A: ation nce Hop
•Cost of A to B = min { 2+0 , 1+3 } = 2 via B.
•Cost of A to C = min { 2+3 , 1+10 } = 5 via B. A 0 A
•Cost of A to D = min { 2+3 , 1+0 } = 1 via D. B 2 B
C 5 B
@ Router B:
•Cost of B to A = min { 2+0 , 3+5 , 3+1 } = 2 via A. D 1 D
•Cost of B to C = min { 2+5 , 3+0 , 3+10 } = 3 via C.
•Cost of B to D = min { 2+1 , 3+10 , 3+0 } = 3 via A.
A 2 A
B 0 B
C 3 C
D 3 A
Destinatio
@ Router C: Distance Next Hop
n
•Cost of C to A = min { 3+2 , 10+1 } = 5 via B.
•Cost of C to B = min { 3+0 , 10+3 } = 3 via B. A 5 B
•Cost of C to D = min { 3+3 , 10+0 } = 6 via B.
B 3 B
C 0 C
@ Router D: D 6 B
•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.
Destination Distance Next Hop
A 1 A
B 3 A
C 6 A
D 0 D
The Count-to-Infinity Problem
• DVR reacts rapidly to good news, but leisurely to bad news
• Routing loops during the time between when the first router realizes a route has failed
until all the routers know that the route has failed. Without the loop-prevention
mechanisms, distance vector protocols can experience a problem called counting to
infinity.
• Routing loops usually occur when any interface goes down
Here each router, will have entries for each other. B will know that it can get to C at a
cost of 1, and A will know that it can get to C via B at a cost of 2.
If the link between B and C is disconnected, then B will know that it can no longer get
to C via that link and will remove it from it’s table. Before it can send any updates it’s
possible that it will receive an update from A which will be advertising that it can get
to C at a cost of 2. B can get to A at a cost of 1, so it will update a route to C via A at a
cost of 3. A will then receive updates from B later and update its cost to 4. They will
then go on feeding each other bad information toward infinity which is called
as Count to Infinity problem.
Link State Routing Algorithm
It is intra-domain routing protocol , the implementation of Link state is Open Shortest Path First (OSPF)
Link State has FIVE steps
1. Discover its neighbors and learn their network addresses.
2. Set the distance or cost metric to each of its neighbors.
3. Construct a packet telling all it has just learned.
4. Send this packet to and receive packets from all other routers.
5. Compute the shortest path to every other router.
(a) A subnet. (b) The link state packets for this subnet.
Link State Routing Algorithm (Contd.,)
Distributing the Link State Packets:
• In this part all the routers gets LSP quickly and reliably
• Uses flooding to distribute the link state packets to all routers
• To keep the flood in check, each packet contains a sequence number that is incremented for each
new packet sent.
• Every Routers keep track of all the (source router, sequence) pairs they received. If new LSP
comes in it is checked against already received , If it is new, it is forwarded on all lines except the
one it arrived on otherwise discarded if duplicate.
• If a packet with a sequence number lower than the highest one seen so far ever arrives, it is
rejected as being obsolete as the router has more recent data.
Problems of LSP:
• First, if the sequence numbers wrap around, confusion will reign. The solution here is to use a 32-
bit sequence number.
Computing the New Routes:
• Dijkstra’s algorithm can be run locally to construct the shortest paths to all possible destinations . The
results of this algorithm tell the router which link to use to reach each destination. This information is
installed in the routing tables, and normal operation is resumed
Hierarchical Routing
Figure gives a quantitative example of routing in a two-level hierarchy with five regions.
Congestion Control
• The presence of too many (excess) packets in (a part of) the network which leads to degradation of
network performance by packet delay and loss is called Network Congestion.
• The responsibility of congestion is shared among Network and Transport layer
• Congestion occurs if network load is greater than the packet handling capacity of the available
resources
• The general solution is to increase the recourse or decrease the load
Congestion Control Techniques
• Links and Routers that are regularly heavily utilized are upgraded at the earliest opportunity. This is
called provisioning.
• Routes may be changed to shift traffic away from heavily used paths by changing the shortest path
weights. This is called Traffic-aware routing.
• In a virtual-circuit network, new connections can be refused if they would cause the network to
become congested. This is called Admission control. These are Open Loop Congestion Control
Congestion Control Techniques (Traffic Throttling)
Traffic Throttling: Reducing the load
The key question for a router drowning in packets is which packets to drop. The preferred
choice may depend on the type of applications that use the network. For a file transfer, an
old packet is worth more than a new one, i.e dropping packet 6 and keeping packets 7
through 10 needs receiver to buffer the packet. This is often called wine
In contrast, for real-time media, a new packet is worth more than an old one. This is
because packets become useless if they are delayed and miss the time at which they must
be played out to the user. This is often called milk
Random Early Detection (RED): In this method routers drop packets early, before the situation has
become hopeless. To determine when to start discarding, routers maintain a running average of their
queue lengths. When the average queue length on some link exceeds a threshold, the link is said to be
congested and a small fraction of the packets are dropped at random.
IPv4 Header Format
IPv4 Header Format
Version: is a 4 bit field that indicates the IP version used. The most popularly used IP versions
are version-4 (IPv4) and version-6 (IPv6). It contains the decimal value 4.
Header length:
• i is a 4 bit field that contains the length of the IP header. It helps in knowing from where the
actual data begins.
• The initial 5 rows of the IP header are always used, So, minimum length of IP header = 5 x 4
bytes = 20 bytes.
• The size of the 6th row representing the Options field vary, The size of Options field can go
up to 40 bytes, So, maximum length of IP header = 20 bytes + 40 bytes = 60 bytes.
Type of service: is a 8 bit field that is used for Quality of Service (QoS) like Low Delay, High
Throughput, Reliability.
Total length: is a 16 bit field that contains the total length of the datagram (in bytes), Length of
header + Data, which has a minimum value 20 bytes and the maximum is 65,535 bytes.
Identification: is a 16 bit field. Unique Packet Id for identifying the group of fragments of a
single IP datagram It is used for the identification of the fragments of an original IP datagram.
IPv4 Header Format
DF bit: stands for Do Not Fragment bit. Its value may be 0 or 1. It indicates the intermediate devices not to
fragment the IP datagram at any cost.
MF bit : stands for More Fragments bit. Its value may be 0 or 1. MF bit = 0, It indicates to the receiver that the
current datagram is either the last fragment in the set or that it is the only fragment. MF bit = 1, It indicates to
the receiver that the current datagram is a fragment of some larger datagram. More fragments are following.
MF bit is set to 1 on all the fragments except the last one. Last Mf=0
Fragment Offset: is a 13 bit field. It indicates the position of a fragmented datagram in the original un-
fragmented IP datagram. The first fragmented datagram has a fragment offset of zero.
Time to live (TTL): is a 8 bit field. It indicates the maximum number of hops a datagram can take to reach the
destination. The main purpose of TTL is to prevent the IP datagrams from looping around forever in a routing
loop.
Protocol: is a 8 bit field. It tells the network layer at the destination host to which protocol the IP datagram
belongs to. In other words, it tells the next level protocol to the network layer at the destination side.
Protocol number of ICMP is 1, IGMP is 2, TCP is 6 and UDP is 17.
Header checksum: is a 16 bit field. It contains the checksum value of the entire header. The checksum value
is used for error checking of the header.
Source IP Address: is a 32 bit field. It contains the logical address of the sender of the datagram.
Destination IP Address: is a 32 bit field. It contains the logical address of the receiver of the datagram.
Quality Of Services (QoS)
QoS is the concept for specifying how “good” the offered services are. Quality of
service is based on the applications using the computer network, the network
performance requirement may vary from application to application
Different N/W will have different packet size. To handle this problem, the packet is divided into
fragments, and each fragment is sent separately. When the fragments reach the destination, they are
reassembled. Then the packet has completed its journey.
Tunneling
Packet Fragmentation
Each network or link imposes some maximum size on its packets. These limits have
various causes, among them
(a)
(b)
Packet Fragmentation
(c)
(a) Original packet, containing 10 data bytes. (b) Fragments after passing through a network
with maximum packet size of 8 payload bytes plus header. (c) Fragments after passing through
a size 5 gateway.
Internet Control Protocols
Dynamic Host Configuration Protocol:
• Every computer in a network has a built-in Ethernet or other link layer address embedded
in the NIC, but no IP address. Assigning IP address manually is tedious and error-prone.
So the better way is to use DHCP (Dynamic Host Configuration Protocol) Server in a
network
• When the server receives the request, it allocates a free IP address and sends it to the host
in a DHCP OFFER packet
• If a host leaves the network and does not return its IP address to the DHCP server, that
address will be permanently lost. After a period of time, many addresses may be lost. IP
address assignment may be for a fixed period of time, a technique called Leasing. Just
before the lease expires, the host must ask for a DHCP renewal.
Internet Control Protocols
ARP—The Address Resolution Protocol:
• Every machine on the Internet has one or more IP addresses, but these addresses are not
sufficient for communicating packets on the network.
• The NICs send and receive frames based on 48-bit Ethernet (MAC) addresses, and NIC
knows nothing about 32-bit IP addresses. So IP address should be mapped on to the MAC
address.
• The Address Resolution Protocol (ARP) is a communication protocol used for discovering
the link layer address, such as a MAC address, associated with a given internet layer address,
typically an IPv4 address.
• The System will then send a broadcast packet to the network using the ARP protocol to ask
"who has This-IP". This broadcast packet, is sent to all all machines on the network to
receive it. Any machine with the requested IP address will reply with an ARP packet that
says "I am having This-IP", and this includes the MAC address which can receive packets
for that IP.
• Systems keep an ARP look-up table where they store information about what IP addresses
are associated with what MAC addresses.
Internet Control Protocols
IMCP—The Internet Control Message Protocol:
When something unexpected occurs during packet processing at a router, the event is reported
to the sender by the ICMP (Internet Control Message Protocol).
ICMP is also used to test the Internet.