Unit 1 3 Network Layer Protocols (1)
Unit 1 3 Network Layer Protocols (1)
LAYER
PROTOCOLS
INTERNET PROTOCOL
(IP)
The network layer in version 4 is one main protocol and three auxiliary ones
Forwarding
The Internet Control Message Protocol version 4 (ICMPv4) helps IPv4 to handle some errors that may
occur in the network-layer delivery
The Internet Group Management Protocol (IGMP) is used to help IPv4 in multicasting
The Address Resolution Protocol (ARP) is used to glue the network and data-link layers in mapping
network-layer addresses to link-layer addresses(MAC)
Position of IP and other network-
layer protocols in TCP/IP
protocol suite
IPv4 is a
connectionle
ss protocol
that uses
the
datagram
approach
Datagram
Format
The format of a packet in which the data coming from the upper layer or
other protocols are encapsulated
payload (data)
Total length of
the datagram
216 = 65535
Header(4 bits)
Version Number The 4-bit version number (VER) field defines the version of the IPv4 protocol,
Header Length
The 4-bit header length (HLEN) field defines the total length of the datagram header in 4-byte words
When a device receives a datagram, it needs to know when the header stops and the data starts which
is
encapsulated in the packet
To make the value of the header length (number of bytes) fit in a 4-bit header length, the total
length of the header is divided by 4 and the value is inserted in the field
The receiver needs to multiply the value of this field by 4 to find the total length
Total Length(4
bits)
This 16-bit field defines the total length (header plus data) of the IP datagram in bytes
A 16-bit number can define a total length of up to 65,535
The size of the datagram is normally much less than this
This field helps the receiving device to know when the packet has completely arrived
To find the length of the data coming from the upper layer, subtract the header length from the
total length
The header length an be found by multiplying the value in the HLEN field by 4
Length of data = total length − (HLEN) × 4
Service Type (differentiated services 8bits)
Service Type
In the original design of the IP header, this field was referred to as type of service (TOS)
Defined how the datagram should be handled (DiffServ)
The DS field contains two subfields: DSCP and CU. The DSCP (Differentiated Services Code Point) is a 6-bit
subfield that defines the per-hop behavior (PHB).
The 2-bit CU (Currently Unused) subfield is not currently used
Ensures
Low loss , Throughput, Low latency, Ensured bandwidth
reliability
Identification, Flags, and
Fragmentation Offset (16 +3+13 bits)
These three fields are related to the fragmentation of the IP datagram
When the size of the datagram is larger than the underlying network can carry
Time-to-live(8
bits)
The time-to-live (TTL) field is used to control the maximum number of hops (routers) visited by the
datagram
When a source host sends the datagram, it stores a number in this field
This value is approximately two times the maximum number of routers between any two hosts
Each router that processes the datagram decrements this number by one
If this value is zero, the router discards the datagram.
Protocol (8
bits)
In TCP/IP, the data section of a packet, called the payload, carries the whole packet from another
protocol
A datagram, can carry a packet belonging to any transport-layer protocol such as UDP , TCP and
a
packet from other protocols that directly use the service of the IP, such as some routing protocols or
some auxiliary protocols
Unique 8-bit number which is inserted in the protocol field.
The value of these fields must remain unchanged during the time the IP datagram travels from
the source host to the destination host
Option
s A datagram header can have up to 40 bytes of options
Options can be used for network testing and debugging
Option processing is required of the IP software
Implementations must be able to handle options if they are present in the header
The existence of options in a header creates burden on the datagram handling: some options can
be changed by routers, which forces each router to recalculate the header checksum
There are one-byte and multi-byte options
Payload (0 to
40bytes)
Payload, or data, is the main reason for creating a datagram
Payload is the packet coming from other protocols that use the service of IP
Payload is the content of the package; the header is only the information written on the package
Exampl
es
An IPv4 packet has arrived with the first 8 bits as (01000010)2 The receiver discards the
packet. Why?
In an IPv4 packet, the value of HLEN is (1000)2. How many bytes of options are being carried by
this packet?
In an IPv4 packet, the value of HLEN is 5, and the value of the total length field is (0028)16. How
many bytes of data are being carried by this packet?
An IPv4 packet has arrived with the first few hexadecimal digits as shown.
(45000028000100000102…)16. How many hops can this packet travel before being dropped? The
data belong to what upper-layer protocol?
An IPv4 packet has arrived with the first 8 bits
as (01000010)2 The receiver discards the
packet. Why?
There is an error in this packet.
The next 4 bits (0010)2 show an invalid header length (2 × 4 = 8). The minimum number of bytes
in the header must be 20. The packet has been corrupted in transmission.
In an IPv4 packet, the value of HLEN is (1000)2. How many bytes of
options are being carried by this packet?
The HLEN value is 8, which means the total number of bytes in the header is 8 × 4, or 32
bytes.
The first 20 bytes are the base header, the next 12 bytes are the options.
In an IPv4 packet, the value of HLEN is 5, and the value of the total length field
is
(0028)16. How many bytes of data are being carried by this packet?
The HLEN value is 5, which means the total number of bytes in the header is 5 × 4, or 20 bytes (no
options)
The total length is (0028)16 or 40 bytes, which means the packet is carrying 20 bytes of data (40 − 20)
An IPv4 packet has arrived with the first few hexadecimal digits as shown.
(45000028000100000102…)16. How many hops can this packet travel before being
dropped? The data belong to what upper-layer protocol?
To find the time-to-live field, we skip 8 bytes (16 hexadecimal digits). The time-to-live field is the
This means the packet can travel only one hop. The protocol field is the next byte (02)16, which
Identification,
flags, and
fragmentation
offset.
Identification (16
bits)
Use to identify fragments of same frame
The combination of the identification and source IP address uniquely define a datagram as it leaves
the source host
IP protocol uses a counter to label the datagrams
The counter is initialized to a positive number. When the IP protocol sends a datagram, it copies
the current value of the counter to the identification field and increments the counter by one.
When a datagram is fragmented, the value in the identification field is copied into all fragments.
3-bit flags field Not Used
D
(Do not
fragment
M
(more
fragment
bit) bit)
The leftmost bit is reserved (not used)
It is the offset of the data in the original datagram measured in units of 8 bytes
Fragmentati
on
Example
◦An IP router with a Maximum Transmission Unit (MTU) of 500 bytes has received an IP packet of
size 3000 bytes (20B + 2980B). How many fragments will be generated. Write M, offset and total
0 1 1 1 1 1 1 (M)
header of length 20 bytes. How many fragments will be generated. Write M, offset and total length (TL)for all
◦Since MTU is 200 bytes and 20 bytes is header size so, maximum length of data = 180 bytes but it can be represented
in fragment offset since not divisible by 8 so, maximum length of data feasible = 176 bytes.
◦ 176/8 =22
P3 P2 P1
20+148 20+176 20+176
168 196 196
0 1 1(M)
44 22 0
ICMPv
4
The ICMPv4 is a message-oriented protocol
ICMPv4 Internet Control Message Protocol version 4 is a Network layer protocol and it report the error to
the source if any problem arises while delivering the datagram from the source host to the destination host
The messages are first encapsulated inside IP datagrams before going to the lower layer
When an IP datagram encapsulates an ICMP message, the value of the protocol field in the IP datagram is
Error-reporting messages
Query messages
Error-reporting messages
The error-reporting messages report problems that a router or a host (destination) may
encounter when it processes an IP packet
The query messages occur in pairs, help a host or a network manager get specific information
from a router or another host
For example
Nodes can discover their neighbors
Hosts can discover and learn about routers on their network
General format of ICMP
messages An ICMP message has an 8-
byte header and a variable-size
data section
First 4 bytes are common to all
For a datagram having a special address such as 127.0.0.0 or 0.0.0.0. (LOOP BACK and 0.0. 0.0 is used on servers to
designate a
service may bind to all network interfaces. It tells a server to "listen" for and accept connections from any
IP address)
All error messages contain a data section that includes the IP header of the original datagram + the first 8 bytes of data in
that datagram
First 8 bytes provide information about the port numbers (UDP and TCP) and sequence number (TCP)
This information is needed so the source can inform the protocols (TCP or UDP) about the error
Contents of data field for the
error messages
Types of Error messages
Destination-unreachable message is sent when a router cannot route or a
host cannot transfer a datagram, the datagram is rejected, and the router or
the host share this back to the source host type 3 code(1-15)
Source Quench informs the sender that the network has encountered
congestion and the datagram has been dropped; the source needs to slow
down sending more datagrams. Flow/congestion control type 4. code(0)
Time exceeded message is generated in two cases−
Whenever a router gets a datagram with a time-to-live value of zero, it
discards the datagram and shares a time exceeded message to the
original source
When the last destination does not obtain all of the fragments in a set
time, it removes the received fragments and sends a time-exceeded
message to the original source type 11 codes(0 and 1)
Parameter Problem Mssage can be sent when either there is a problem in the
header of a datagram (code 0) or some options are missing or cannot be
interpreted type 12 (code 1)
The redirection message is used when the source uses a wrong router to send
out its message. The router redirects the message to the appropriate router, but
informs the source that it needs to change its default router in the future. The IP
address of the default router is sent in the message (type 5 code 0 and 3)
Query
Messages
Query messages are used to probe or test the
liveliness of hosts or routers in the Internet
Find the one-way or the round-trip time for an IP datagram between two devices
The echo request (type 8) and the echo reply (type 0) pair of messages are used by a host or a router to test the
time between two devices or to check whether the clocks in two devices are synchronized
The timestamp request message sends a 32-bit number, defines the time the message is sent.
The timestamp reply resends that number, but also includes two new 32-bit numbers representing the time the request was
received and the time the response was sent
If all timestamps represent Universal time, the sender can calculate the one-way and round-trip time
Debugging
Tools
Several tools that can be used in the Internet for debugging
Ping
Traceroute
Ping(Packet Internet or Inter-
Network Groper)
Use the ping program to find if a host is alive and responding
Example:
The source host sends ICMP echo-request messages; the destination, if alive, responds with ICMP echo-reply
messages
The ping program sets the identifier field in the echo-request and echo-reply message and starts the sequence
number from 0; this number is incremented by 1 each time a new message is sent(total 4)
When the packet arrives, it subtracts the arrival time from the departure time to get the round-trip time
(RTT)
Ping
Ipconfig/all
Traceroute or
Tracert
The traceroute program in UNIX or tracert in Windows can be used to
Traceroute is a network diagnostic tool used to track in real-time the pathway taken by a packet on an IP
network from source to destination, reporting the IP addresses of all the routers it pinged in between
Traceroute also records the time taken for each hop the packet makes during its route to the destination.
It can find the IP addresses of all the routers that are visited along the path
The program is usually set to check for the maximum of 30 hops (routers) to be visited
time-exceeded
destination-unreachable.
If there are n routers in the path, the traceroute program sends (n + 1) messages
The first n messages are discarded by the n routers, one by each router the last message is
The traceroute client program uses the (n + 1) ICMP error-reporting messages received to find
destination
traceroute programs send three messages to each device, with the same TTL value, to be able to find
and 2nd to 4th time in milliseconds round trip time (RRT) for each intermediate hop
traceroute command sends three packets to each hop and each of the time refers to RRT
Difference between Ping And Tracert
◦ https://www.youtube.com/watch?v=up3bcBLZS74
Example of checksum
calculation
ICMP the checksum is calculated over
request message
The message is divided into 16-bit
(2-
byte) words
The words are added and the sum
is
complemented
Sender put this value in the checksum
field
MOBILE
IP
Mobile and personal computers become increasingly popular, we need to think about mobile IP
The extension of IP protocol that allows mobile computers to be connected to the Internet at any
location where the connections possible
Addressing
The main problem that must be solved in providing mobile communication using the IP protocol is
addressing
Stationary Hosts and Mobile
Hosts
Stationary Hosts
The original IP addressing was based on the assumption that a host is stationary, attached to one
specific network
A router uses an IP address to route an IP datagram
An IP address has two parts: a prefix and a suffix. The prefix associates a host with a network.
This implies that a host in the Internet does not have an address that it can carry with itself
from
one place to another
The address is valid only when the host is attached to the network. If the network changes, the
address is no longer valid
Mobile Hosts
When a host moves from one network to another, the IP addressing structure needs to be
modified.
Solutions
1. Changing the Address
One simple solution is to let the mobile host change its address as it goes to the new network
The host can use DHCP to obtain a new address to associate it with the new network
Drawbacks
The configuration files would need to be changed
Each time the computer moves from one network to another, it must be rebooted.
The DNS tables need to be revised so that every other host in the Internet is aware of the change
If the host roams from one network to another during a transmission, the data exchange will be interrupted
because the ports and IP addresses of the client and the server must remain constant for the duration of the
connection
Solutions
◦ 2. Two Addresses
Use of two addresses home address and care-of address
The host has its original address, called the home address and a temporary address, called the
care-of address
The home address is permanent; it associates the host with its home network, the network that is
the permanent home of the host
The care-of address is temporary. When a host moves from one network to another, the care-of
address changes; it is associated with the foreign network, the network to which the host moves
Home address and care-of address
Mobile IP has two addresses for a mobile host: one home address and
one care-of address
The home address is permanent; the care-of address changes as the
mobile host moves from one network to another
Agent
s
To make the change of address transparent to the rest of the Internet requires a
Home agent relative to the home network and a foreign agent relative to the foreign network
Home Agent
The home agent is usually a router attached to the home network of the mobile host.
The home agent acts on behalf of the mobile host when a remote host sends a
The home agent receives the packet and sends it to the foreign agent
Foreign Agent
The foreign agent receives and delivers packets sent by the home agent to the mobile
host
Collocated care-of
address
When the mobile host acts as a foreign agent, the care-of address is called a
collocated care-of
address
The advantage of using a collocated care-of address is that the mobile host can
move to any
The disadvantage is that the mobile host needs extra software to act as its own
foreign agent
Three
Phases
To communicate with a remote
Agent discovery
Registration
Data transfer
Agent
Discovery
Agent discovery, consists of two sub phases
A mobile host must discover /learn the address of a home agent before it leaves its home network
A mobile host must discover a foreign agent after it has moved to a foreign network
Advertisement
Solicitation
Agent
Advertisement
When a router advertises its presence on a network using an ICMP router
It can use the ICMP solicitation message to inform an agent that it needs assistance
Mobile IP does not use a new packet type for agent solicitation; it uses the router solicitation packet
of ICMP
Registratio
n second phase in mobile communication is registration
The
After a mobile host has moved to a foreign network and discovered the foreign agent, it must register
There are four aspects of registration:
The mobile host must register itself with the foreign agent
The mobile host must register itself with its home agent. This is normally done by the foreign agent on behalf
of the mobile host
The mobile host must renew registration if it has expired
The mobile host must cancel its registration (deregistration) when it returns home
Registratio
nand Reply
Request
To register with the foreign agent and the home agent, the mobile host uses a registration request and
foreign agent reply
Registration Request
When registering using a foreign agent, the registration process takes the following steps
The mobile node sends a registration request to the foreign agent to begin the registration process
The foreign agent processes the registration request and then relays it to the home agent
Registration Reply
A registration reply is sent from the home agent to the foreign agent and then relayed to the mobile
host
The reply confirms or denies the registration request
“A registration request or reply is sent by UDP using the well-known port 434.”
Registration request Type The 8-bit type field defines the type of message.
format For a
request message the value of this field is 1.
❑ Flag The 8-bit flag field defines forwarding information.
The value
of each bit can be set or unset
Lifetime. This field defines the number of seconds the
registration is valid. If the field is a string of 0s, the
request message is asking for deregistration. If the
Registration request flag field field is a string of 1s, the lifetime is infinite.
bits ❑ Home address. This field contains the permanent (first)
address of
the mobile host.
❑ Home agent address. This field contains the address of the
home
agent.
❑Care-of address. This field is the temporary (second)
address of the mobile host.
❑Identification. This field contains a 64-bit number that is
inserted into the request by the mobile host and
repeated in the reply message. It matches a request
with a reply.
Registration reply The fields are similar to those of the registration
request with the following exceptions.
format The value of the type field is 3
The code field replaces the flag field and shows
the result of
the registration request (acceptance or denial).
The care-of address field is not needed
Data transfer
From Remote Host to Home Agent
From Home Agent to Foreign Agent
From Foreign Agent to Mobile Host
Data From Mobile Host to Remote Host
transfer
Transparency
The remote host is unaware of any
movement
by the mobile host
The remote host sends pac kets
using the home address of the
mobile host as the destination
address
Remote receives packets that have
the home address of the mobile host as
the source address
Inefficiency in
Mobile IP
Communication involving mobile IP can be inefficient
Solutio
n
One solution to inefficiency is for the remote host to bind the care-of
address to the
home address of a mobile host
For example, when a home agent receives the first packet for a
mobile host, it forwards the packet to the foreign agent; it could also
send an update binding packet to the remote host so that future
packets to this host could be sent to the care-of address. The remote
host can keep this information in a cache.
The problem with this strategy is that the cache entry becomes
outdated once the mobile host moves.
In this case the home agent needs to send a warning packet to the
remote host to inform it of the change