CSIE,NTUT,TAIWAN 1
Internet Protocol (IP)
Chuan-Ming Liu
CSIE,NTUT
Spring ’04,TAIWAN
CSIE,NTUT,TAIWAN 2
CONTENTS
DATAGRAM
FRAGMENTATION
OPTIONS
CHECKSUM
IP PACKAGE
CSIE,NTUT,TAIWAN 3Figure 8-1
Position of IP in TCP/IP protocol suite
CSIE,NTUT,TAIWAN 4
Internet Protocol (IP)
Unreliable
Connectionless
Best-effort delivery
No error checking
CSIE,NTUT,TAIWAN 5
DATAGRAM
8.1
CSIE,NTUT,TAIWAN 6
Datagram
Packets in the IP layer are called datagrams.
The lengths of different datagrams vary
A datagram consists of two parts:
– Header
– Data
The header
– is 20-60 bytes in length
– contains information for routing
CSIE,NTUT,TAIWAN 7Figure 8-2
IP datagram
CSIE,NTUT,TAIWAN 8
IP Headers
4-byte section presentation
Fields includes:
– Version (VER)
– Header length (HLEN)
– Differential Services (DS),or service types (ST)
– Total length
– Identification
– Flags
– Fragmentation offset
– Time to live
– Protocol
– Checksum
– Source and Destination IP address
CSIE,NTUT,TAIWAN 9Figure 8-2
IP datagram
CSIE,NTUT,TAIWAN 10
IP Headers
VER HLEN DS(ST) TOTAL LENGTH
FLAGS
TIME TO LIVE
IDENTIFICATION
PROTOCOL HEADER CHECKSUM
FRAGMENT OFFSET
SOURCE IP ADDRESS
DESTINATION IP ADDRESS
OPTIONS
0 4 8 16 19 24 31
CSIE,NTUT,TAIWAN 16
Total Length
16-bit field
Total length = header length + length of data
Limited to 65,535 bytes
Some physical networks are not able to
encapsulate a datagram of 65,535 bytes
CSIE,NTUT,TAIWAN 17
The total length field defines the
total length of the
datagram including the header.
CSIE,NTUT,TAIWAN 18
Time to Live (TTL)
Specifies how long,originally in seconds,the
datagram is allowed to remain in the internet
Routers and hosts that process datagrams must
decrement this field as time passes
The datagram was discarded when the value
became zero
Today,this field is mostly used to control the
maximum number of hops visited by the
datagram
CSIE,NTUT,TAIWAN 19
Protocol
Higher-level protocol that uses the services of
the IP layer
Several higher-level protocols such as TCP,
UDP,ICMP,and IGMP.
CSIE,NTUT,TAIWAN 20Figure 8-5
Multiplexing
CSIE,NTUT,TAIWAN 21
Example 1
An IP packet has arrived with the first 8 bits
as shown:
01000010
The receiver discards the packet,Why?
CSIE,NTUT,TAIWAN 22
Solution
There is an error in this packet,The 4 left-most
bits (0100) show the version,which is correct,The
next 4 bits (0010) show the header length,which
means (2? 4 = 8),which is wrong,The minimum
number of bytes in the header must be 20,The
packet has been corrupted in transmission.
CSIE,NTUT,TAIWAN 23
Example 2
In an IP packet,the value of HLEN is 1000
in binary,How many bytes of options are
being carried by this packet?
CSIE,NTUT,TAIWAN 24
Solution
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 main header,the next 12
bytes are the options.
CSIE,NTUT,TAIWAN 25
Example 3
In an IP packet,the value of HLEN is 516
and the value of the total length field is
002816,How many bytes of data are being
carried by this packet?
CSIE,NTUT,TAIWAN 26
Solution
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 40 bytes,which
means the packet is carrying 20 bytes of data (40-
20).
CSIE,NTUT,TAIWAN 27
Example 4
An IP packet has arrived with the first few
hexadecimal digits as shown below:
45000028000100000102...................
How many hops can this packet travel before
being dropped? The data belong to what
upper layer protocol?
CSIE,NTUT,TAIWAN 28
Solution
To find the time-to-live field,we should skip 8
bytes (16 hexadecimal digits),The time-to-live
field is the ninth byte,which is 01,This means the
packet can travel only one hop,The protocol field
is the next byte (02),which means that the upper
layer protocol is IGMP.
CSIE,NTUT,TAIWAN 29
FRAGMENTATION
8.2
CSIE,NTUT,TAIWAN 30
Fragmentation
Maximum Transfer Unit (MTU)
Fragmentation and reassembly
Fields related to fragmentation
CSIE,NTUT,TAIWAN 31
Maximum Transfer Unit (MTU)
One of the fields in data link layer protocol
defines the maximum size of the data field
IP protocol package makes the maximum
length of the IP datagram equal to the MTU
So far,MTU is 65535
Dividing the datagram to fit the MTU is
necessary for data to pass through the
networks having different MTUs
CSIE,NTUT,TAIWAN 32
Fragmentation
Dividing a datagram into a set of smaller
datagrams is called fragmentation
Fragmented datagram (fragment) can be
further divided if necessary
Each fragment has its own header with most of
the fields repeated
Reassembly of the fragmented datagrams is
done only by the destination host
CSIE,NTUT,TAIWAN 33
IP Headers
VER HLEN DS(ST) TOTAL LENGTH
FLAGS
TIME TO LIVE
IDENTIFICATION
PROTOCOL HEADER CHECKSUM
FRAGMENT OFFSET
SOURCE IP ADDRESS
DESTINATION IP ADDRESS
OPTIONS
0 4 8 16 19 24 31
CSIE,NTUT,TAIWAN 34
Fields Related to Fragmentation
Identification (16-bit field)
– Identifying the original datagram from the source
– Combination of the identification and the source IP
address is uniquely defined for a datagram
Flags (3-bit field)
– Do not fragment bit
– More fragment bit
Fragment offset (13-bit field)
– Relative position to the whole datagram
– Measured in units of 8 bytes
CSIE,NTUT,TAIWAN 35
Reassembly
The first fragment has an offset 0
Divided the length of the first fragment by 8;
the second fragment has an offset equal to that
Divided the length of the second fragment by 8;
the third fragment has an offset equal to that
Repeat the process until the last fragment has a
more bit 0
CSIE,NTUT,TAIWAN 40
Example 5
Apacket has arrived with anMbit value of 0.
Is this the first fragment,the last fragment,
or a middle fragment? Do we know if the
packet was fragmented?
CSIE,NTUT,TAIWAN 41
Solution
If the M bit is 0,it means that there are no more
fragments; the fragment is the last one,However,
we cannot say if the original packet was
fragmented or not,A nonfragmented packet is
considered the last fragment.
CSIE,NTUT,TAIWAN 42
Example 6
Apacket has arrived with anMbit value of 1.
Is this the first fragment,the last fragment,
or a middle fragment? Do we know if the
packet was fragmented?
CSIE,NTUT,TAIWAN 43
Solution
If the M bit is 1,it means that there is at least one
more fragment,This fragment can be the first one
or a middle one,but not the last one,We don’t
know if it is the first one or a middle one; we need
more information (the value of the fragmentation
offset),However,we can definitely say the original
packet has been fragmented because the M bit
value is 1.
CSIE,NTUT,TAIWAN 44
Example 7
Apacket has arrived with anMbit value of 1
and a fragmentation offset value of zero,Is
this the first fragment,the last fragment,or a
middle fragment?
CSIE,NTUT,TAIWAN 45
Solution
Because the M bit is 1,it is either the first
fragment or a middle one,Because the offset value
is 0,it is the first fragment.
CSIE,NTUT,TAIWAN 46
Example 8
A packet has arrived in which the offset
value is 100,What is the number of the first
byte? Do we know the number of the last
byte?
CSIE,NTUT,TAIWAN 47
Solution
To find the number of the first byte,we multiply
the offset value by8,This means that the first byte
number is 800,We cannot determine the number of
the last byte unless we know the length of the data.
CSIE,NTUT,TAIWAN 48
Example 9
A packet has arrived in which the offset
value is 100,the value of HLEN is 5 and the
value of the total length field is 100,What is
the number of the first byte and the last byte?
CSIE,NTUT,TAIWAN 49
Solution
The first byte number is 100? 8 = 800,The total
length is 100 bytes and the header length is 20
bytes (5? 4),which means that there are 80 bytes
in this datagram,If the first byte number is 800,
the last byte number must 879.
CSIE,NTUT,TAIWAN 50
OPTIONS
8.3
CSIE,NTUT,TAIWAN 51
Options
Not required for every datagram
Up to 40 bytes
For testing and debugging
Standards should be able to handle options
Consists of
– 1-byte code field
– 1-byte length field
– Variable-sized data field
CSIE,NTUT,TAIWAN 52Figure 8-10
Option format
CSIE,NTUT,TAIWAN 53
Options – Code Field
8-bit
Three subfields:
– Copy (1-bit),controls the presence of the option
– Class (2-bit),defines the general purpose of the
option
– Number (5-bit),defines the type of the option
CSIE,NTUT,TAIWAN 54
Options – Length Field
defines the total length of the option
Options – Data Field
data specifying options require
CSIE,NTUT,TAIWAN 55
Option Types
No option
End of option
Record route
Strict source route
Loose source route
Timestamp
CSIE,NTUT,TAIWAN 56Figure 8-11
Categories of options
CSIE,NTUT,TAIWAN 57Figure 8-12
No operation option
CSIE,NTUT,TAIWAN 58Figure 8-13
End of option option
CSIE,NTUT,TAIWAN 59Figure 8-14
Record route option
CSIE,NTUT,TAIWAN 60Figure 8-15
Record route concept
CSIE,NTUT,TAIWAN 61Figure 8-16
Strict source route option
CSIE,NTUT,TAIWAN 62Figure 8-17
Strict source route concept
CSIE,NTUT,TAIWAN 63Figure 8-18
Loose source route option
CSIE,NTUT,TAIWAN 64Figure 8-19
Timestamp option
CSIE,NTUT,TAIWAN 65Figure 8-20
Use of flag in timestamp
CSIE,NTUT,TAIWAN 66Figure 8-21
Timestamp concept
CSIE,NTUT,TAIWAN 67
Example 10
Which of the six options must be copied to
each fragment?
CSIE,NTUT,TAIWAN 68
Solution
We look at the first (left-most) bit of the code for
each option.
No operation,Code is 00000001;no copy.
End of option,Code is 00000000;no copy.
Record route,Code is 00000111;no copy.
Strict source route,Code is 10001001;copied.
Loose source route,Code is 10000011;copied.
Timestamp,Code is 01000100;no copy.
CSIE,NTUT,TAIWAN 69
Example 11
Which of the six options are used for
datagram control and which are used for
debugging and management?
CSIE,NTUT,TAIWAN 70
Solution
We look at the second and third (left-most) bits of
the code.
No operation,Code is 00000001;control.
End of option,Code is 00000000;control.
Record route,Code is 00000111;control.
Strict source route,Code is 10001001;control.
Loose source route,Code is 10000011;control.
Timestamp,Code is 01000100;debugging
CSIE,NTUT,TAIWAN 71
CHECKSUM
8.4
CSIE,NTUT,TAIWAN 72
Checksum
Error detection method used by most TCP/IP
protocols
Checksum is calculated at the sender
CSIE,NTUT,TAIWAN 73
To create the checksum the sender does
the following:
1,The packet is divided into k sections,
each of n bits.
2,All sections are added together using
one’s complement arithmetic.
3,The final result is complemented
to make the checksum.
CSIE,NTUT,TAIWAN 74Figure 8-22
Checksum concept
CSIE,NTUT,TAIWAN 75Figure 8-23
Checksum in one’s complement arithmetic
CSIE,NTUT,TAIWAN 76Figure 8-24
Example of
checksum
calculation
in binary
CSIE,NTUT,TAIWAN 77
Check Appendix C for a detailed
description of checksum calculation
and the handling of carries.
CSIE,NTUT,TAIWAN 78
IP PACKAGE
8.5
CSIE,NTUT,TAIWAN 79
Figure 8-26 IP
components
CSIE,NTUT,TAIWAN 80
Figure 8-27 MTU table
CSIE,NTUT,TAIWAN 81
Figure 8-28
Reassembly table