0% found this document useful (0 votes)
6 views

Ch4.G CN Network Layer

Uploaded by

Aakrit Dongol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Ch4.G CN Network Layer

Uploaded by

Aakrit Dongol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Computer Networks

(CT 702)
Sharad Kumar Ghimire
Department of Electronics and Computer Engineering
Pulchowk Campus
Institute of Engineering
Tribhuvan University
Nepal
Chapter 4

Network Layer
Contd...

S. K. Ghimire
Contents

Protocols:

● IP
● ICMP
○ Debugging tools using ICMP

- S. K. Ghimire
Protocols
TCP/IP Protocol Suits
Internet Protocol

IPv4
Internet Protocol: IPv4
Connectionless protocol for a packet-switching network

Uses the datagram approach

Each datagram is handled independently, each datagram can follow a different


route to the destination

The datagrams sent by the same source to the same destination could arrive out
of order and some could be lost or corrupted during transmission

IP relies on a higher-level protocol to take care of all these problems

IPv4 datagram - variable-length packet consisting of header and data


IPv4 Packet Header
Fields of IP Header
Version (VER) (4 bits)

● 4-bit field - version of IP protocol


● version 4 and version 6

Header length (HLEN) (4 bits)

● 4-bit field
● Defines the total length of the datagram header in 4-byte words
● As the length of the header is variable (between 20 and 60 bytes)
● When there are no options, the header length is 20 bytes so the value of this
field is 5 (5 x 4 = 20) at min, and the value of this field is 15 (15 x 4 = 60) at
max
Type of Service (8 bits)

● The field that has changed its meaning (slightly) over the years
● It was and is still intended to distinguish between different classes of service
● Various combinations of reliability and speed are possible
● For digitized voice, fast delivery beats accurate delivery
● For file transfer, error-free transmission is more important than fast
transmission
Total Length (16 bits)

● Defines the total length of the datagram including the header, in octets
● The maximum length is 65,535 bytes
● Length of data = Total length – Header length

= Total Length – 4 × IHL


Identification (16 bits)

● Used to identify a datagram uniquely


● A sequence number that, together with the source address, destination
address, and user protocol are used for unique identification of a datagram
● This field is needed to allow the destination host to determine which datagram
a newly arrived fragment belongs to
● All the fragments of a datagram contain the same Identification value
Flags (3 bits)

● Only two of the bits are defined


● MF: More Fragments and used for fragmentation & reassembly
○ All fragments except the last one have this bit set
○ Used to know when all fragments of a datagram have arrived
● DF: Don’t Fragment & prohibits fragmentation when set
○ It is used when the destination does not have the capability to
reassemble fragments, and when this bit is set, the datagram will be
discarded if it exceeds the maximum size of an en-route network
Fragment offset (13 bits)

● Indicates where in the current datagram this fragment belongs


● Measured in 64-bit units
● All fragments except the last one in a datagram must be a multiple of 8 bytes,
the elementary fragment unit
● Since 13 bits are provided, there is a maximum of 8192 fragments per
datagram, giving a maximum datagram length of 65,536 bytes
● Fragments other than the last fragment must contain a data field that is a
multiple of 64 bits in length
Time to Live (8 bits)

● A counter used to limit packet lifetimes


● It is decremented on each hop and is supposed to be decremented multiple
times when queued for a long time in a router
● When it hits zero, the packet is discarded and a warning packet is sent back
to the source host
● Prevents datagrams from wandering around forever
Protocol (8 bits)

● Indicates the next higher level protocol that is to receive the data field at the
destination
● Tells which transport protocol is carried by IP packet
● The numbering of protocols is global across the entire Internet
● Examples TCP = 6; UDP = 17; ICMP = 1
● A complete list is at: http://www.iana.org/assignments/protocol-numbers
Header checksum (16 bits)

● Used as error detecting code to verify the header


● The Header checksum must be recomputed at each hop because at least one
field always changes (the Time to live field), but tricks can be used to speed
up the computation
Source Address (32 bits): Network number and host number of source machine

Destination Address (32 bits): Network number and host number of destination
machine

Options (variable): Encodes the options requested by the sending user

Padding (variable): Used to have the datagram header in a multiple of 32 bits

Data (variable): The data field must be an integer multiple of 8 bits in length and
the maximum length of the datagram is 65,535 octets (data field plus header)
ICMP

Internet Control Message Protocol


What happens if something goes wrong?
● What happens if a router must discard a datagram because it cannot find a
route to the final destination, or because the time-to-live field become zero?
● What happens if the final destination host must discard all fragments of a
datagram because it has not received all fragments within a predetermined
time limit?
● IP protocol has no built-in mechanism to notify the original host
● IP protocol also lacks a mechanism for host and management queries
● A host sometimes needs to determine if a router or another host is alive
● Network administrator may need information from another host or router
● Internet Control Message Protocol (ICMP) is designed for such purpose
ICMP
A mechanism used by hosts, gateways and other intermediate routers to send
notification of datagram problems back to the sender

Sends query and error reporting messages

Provides a means for transferring messages from routers and other hosts to a
host

ICMP provides feedback about problems in the communication environment

In most cases, an ICMP message is sent in response to a datagram, either by a


router along the datagram’s path or by the intended destination host
ICMP Message
Position of ICMP in the network layer

ICMP encapsulation
ICMP Message Format

8-byte header and a variable-size data section

The format of the header is different for each message type, the first 4 bytes are
common to all

First field, type, defines the type of the message

The code field specifies the reason for the particular message type

The last common field is the checksum field

The rest of the header is specific for each message type


Types of ICMP messages

Two categories

● Error-reporting, e.g. ● Query messages, e.g.


○ Destination unreachable ○ Echo request or reply
○ Source quench ○ Timestamp request or reply
○ Time exceeded
○ Parameter problem
ICMP: Error Reporting
ICMP Error: Destination Unreachable
When a router cannot route a datagram or a host cannot deliver a datagram, the
datagram is discarded and the router or the host sends a destination-unreachable
message back to the source host that initiated the datagram

The destination-unreachable messages can be created by either a router or the


destination host
ICMP Error: Source Quench
If the datagrams are received much faster than they can be forwarded or
processed, the queue may overflow, so in such case, the router or the host has no
choice but to discard some of the datagrams

ICMP-Source-quench is designed to add a kind of flow control to the IP

When a router or host discards a datagram due to congestion, it sends a source-


quench message to the sender of the datagram
ICMP Error: Time Exceeded

Whenever a router decrements a datagram with a time-to-live value to zero, it


discards the datagram and sends a time-exceeded message to the original source

When the final destination does not receive all of the fragments in a set time, it
discards the received fragments and sends a time-exceeded message to the
original source
ICMP Error: Parameter Problem
Any ambiguity in the header part of a datagram can create serious problems as
the datagram travels through the Internet

If a router or the destination host discovers an ambiguous or missing value in any


field of the datagram, it discards the datagram and sends a parameter-problem
message back to the source
ICMP Error: Redirection

Usually a host has a very limited number of route entries; i.e. it knows the IP
address of only one router, the default gateway

When a host send a datagram, which is destined for another network, to the
wrong router, the router that receives the datagram will forward the datagram to
the correct router

However, to update the routing table of the host, it sends a redirection message to
the host
ICMP: Query Messages
ICMP can be used to diagnose some network problems via the query messages
ICMP: Echo Request and Reply
The echo-request and echo-reply messages are designed for diagnostic purposes

Used to identify network problems

The combination of echo-request and echo-reply messages are used whether two
systems (hosts or routers) can communicate with each other

The echo-request and echo-reply messages can be used to determine if there is


communication at the IP level
ICMP: Timestamp Request and Reply
Two machines (hosts or routers) can use the timestamp request and timestamp
reply messages to determine the round-trip time needed for an IP datagram to
travel between them

It can also be used to synchronize the clocks in two machines


ICMP: Address-Mask Request and Reply
To obtain subnet mask, a host sends an address-mask-request message to a
router on the LAN

If the host knows the address of the router, it sends the request directly to the
router but if it does not know, it broadcasts the message

The router receiving the address-mask-request message responds with an


address-mask-reply message, providing the necessary mask for the host
ICMP: Router Solicitation and Advertisement
The router-solicitation and router-advertisement messages can help to know if the
routers are alive and functioning by host

A host can broadcast (or multicast) a router-solicitation message

The router or routers that receive the solicitation message broadcast their routing
information using the router-advertisement message

A router can also periodically send router-advertisement messages even if no host


has solicited
Debugging Tools using ICMP
Ping

Can be used to find if a host is alive and responding

The source sends ICMP echo-request messages; the destination, if alive,


responds with ICMP echo-reply messages

Can calculate the round-trip time also


Traceroute
UNIX/Linux/Cisco: traceroute

Windows: tracert

Used to trace the route of a packet from the source to the destination

This is used in conjunction with ICMP packets

To find the route of a packet it uses two ICMP messages, time exceeded and
destination unreachable

This is a program at the application level that uses the services of UDP

You might also like