Vous êtes sur la page 1sur 68

Chapter 8

Internet Protocol
Objectives
Upon completion you will be able to:
Understand the format and fields of a datagram
Understand the need for fragmentation and the fields involved
Understand the options available in an IP datagram
Be able to perform a checksum calculation
Understand the components and interactions of an IP package
TCP/IP Protocol Suite

Figure 8.1

Position of IP in TCP/IP protocol suite

IP: connectionless, unreliable, packet switching w/ datagrams besteffort delivery service


TCP/IP Protocol Suite

Internet Protocol (IP) is the transmission


mechanism used by the TCP/IP protocols at the
network layer.

The term best-effort means that IP packets can


be corrupted, lost, arrive out of order, or delayed
and may create congestion for the network.

TCP/IP Protocol Suite

8.1 DATAGRAM
A packet in the IP layer is called a datagram,
a variable-length packet consisting of two parts: header and data.
The header is 20 to 60 bytes in length and contains information essential
to routing and delivery.
Some of the fields:
VER - version numbers, 4 and 6
HLEN - header length in 4-byte words. Value of 5 means 20 byte header

TCP/IP Protocol Suite

Figure 8.2

TCP/IP Protocol Suite

IP datagram

Figure 8.3

Service type or Differentiated Services - DS field

This field was previously called Service type. Now called


Differentiated Services.
The precedence subfield was designed,
but never used in version 4.
TOS (Type of Service) bits - see next slide.

TCP/IP Protocol Suite

Table 8.1 Types of service

If you want to send a packet with a special type of service,


use one of the above 5-bit sets.

TCP/IP Protocol Suite

Table 8.2 Default types of service


Some apps
have default
service types.

TCP/IP Protocol Suite

If we call these 8 bits Differentiated Services (and not the


older Service Type), then the first six bits are called codepoints.

Table 8.3 Values for codepoints

When the 3 right-most bits are 0, the 3 left-most bits are the sam
as the precedence bits from the previous slides.
When the 3 right-most bits are not all 0s, the 6 bits define 64
Services based on the priority assignment by the Internet or
local authorities. Assignments have not yet been finalized.
TCP/IP Protocol Suite

Figure 8.4

Encapsulation of a small datagram in an Ethernet frame

The total length field defines the total length of the datagram
including the header.
Total length field is 16 bits, or 65,535 bytes. Of which 20 to
60 bytes are the header.
If an IP datagram is short, and is packaged into an Ethernet
frame, remember that the minimum payload size of an
Ethernet frame is 46 bytes.

TCP/IP Protocol Suite

10

Identification, Flags, and Fragmentation offset are all used


to perform fragmentation, which we will cover shortly.
Time to Live - 8-bit field, so Time to Live can be set to 255.
As it passes thru a router, the router decrements the
counter. When counter hits 0, the datagram is deleted
(and ICMP sends an error message back to the source).

Time to live. A datagram has a limited lifetime in its travel through an interne
field was originally designed to hold a timestamp, which was decremented by
visited router. The datagram was discarded when the value became zero.
Why might a host set the Time to Live field to 1?

TCP/IP Protocol Suite

11

Figure 8.5

Multiplexing

The Protocol field (8 bits) identifies the upper layer protocol


that is using IP for transmission of its data.

TCP/IP Protocol Suite

12

Table 8.4 Protocols

TCP/IP Protocol Suite

13

Example 1
An IP packet has arrived with the first 8 bits as shown:

01000010
The receiver discards the packet. Why?

TCP/IP Protocol Suite

14

Example 1
An IP packet has arrived with the first 8 bits as shown:

01000010
The receiver discards the packet. Why?
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.
TCP/IP Protocol Suite

15

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?

TCP/IP Protocol Suite

16

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?

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
base header, the next 12 bytes are the options.

TCP/IP Protocol Suite

17

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?

TCP/IP Protocol Suite

18

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?
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).

TCP/IP Protocol Suite

19

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?

TCP/IP Protocol Suite

20

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?
Solution
To find the time-to-live field, we 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 (see Table 8.4).
TCP/IP Protocol Suite

21

8.2 FRAGMENTATION
The format and size of a frame depend on
physical network. A datagram may have to
protocol regulations.

the protocol used


be fragmented to

by
fit

the
the

The topics discussed in this section include:


Maximum Transfer Unit (MTU)
Fields Related to Fragmentation

TCP/IP Protocol Suite

22

Figure 8.6

MTU

MTU - Maximum Transfer Unit

TCP/IP Protocol Suite

23

Table 8.5 MTUs for some networks

Max datagram size for IP is 65535 bytes. So if we have a max


sized datagram to send over Ethernet, what do we do?
TCP/IP Protocol Suite

24

Figure 8.7

Flags field

A datagram can be fragmented by the source host or any


router in the path. Reassembly is done only by the destination
host.
Most fields are copied from one fragment to the next. The 3
fields that are not copied are the flags, fragmentation offset,
and the total length.
(And the checksum of course is recalculated.)
* The Identification field is copied from one fragment to the
next.
The Do Not Fragment bit is set to 1 if the network is not
supposed
to fragment this datagram. (If it has to be fragmented, it is
tossed.) The More Fragments bit is set to 1 if there are more
fragments
following this one.
TCP/IP Protocol Suite

25

Figure 8.8

Fragmentation example

The Fragmentation Offset tells what position this fragment


is in the whole stream. The offset counts by 8. So if a
fragment is supposed to start at byte 400, the offset equals
50.

* It is the offset of the data in the original datagram measure


in units of 8 bytes

TCP/IP Protocol Suite

26

Figure 8.9

TCP/IP Protocol Suite

Detailed fragmentation example

27

Example 5
A packet has arrived with an M bit value of 0. Is this the first
fragment, the last fragment, or a middle fragment? Do we
know if the packet was fragmented?

TCP/IP Protocol Suite

28

Example 5
A packet has arrived with an M bit value of 0. Is this the first
fragment, the last fragment, or a middle fragment? Do we
know if the packet was fragmented?

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 non-fragmented packet is
considered the last fragment.

TCP/IP Protocol Suite

29

Example 7
A packet has arrived with an M bit value of 1 and a
fragmentation offset value of zero. Is this the first fragment,
the last fragment, or a middle fragment?.

TCP/IP Protocol Suite

30

Example 7
A packet has arrived with an M bit value of 1 and a
fragmentation offset value of zero. Is this the first fragment,
the last fragment, or a middle fragment?.
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.

TCP/IP Protocol Suite

31

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?

TCP/IP Protocol Suite

32

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?
Solution
To find the number of the first byte, we multiply the offset
value by 8. 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.

TCP/IP Protocol Suite

33

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?

TCP/IP Protocol Suite

34

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?
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 be 879.

TCP/IP Protocol Suite

35

8.3 OPTIONS
The header of the IP datagram is made of two parts: a fixed part and a
variable part. The variable part comprises the options that can be a
maximum of 40 bytes.

The topics discussed in this section include:


Format
Option Types

TCP/IP Protocol Suite

36

Figure 8.10

Option format

Not all routers/hosts use these options, but they must be


ready to do so if they are present in the datagram.

Copy - tells whether to copy this option into a fragment


Class - defines the general purpose of the option
TCP/IP Protocol Suite

37

Figure 8.11 Categories of options

As we just saw, only 6 options in use currently. The single-b


options are only 1 byte in length and do not require length o
data fields.

TCP/IP Protocol Suite

38

Figure 8.12

No operation option

* Used as a filler between options. For


example,
1.can be used to align the next option .
2.Can be used to align beginning of an
option .
on a 16- or 32-bit boundary.

TCP/IP Protocol Suite

39

Figure 8.13

End of option option

* Denotes the end of the options and that the data is


next.
* used for padding at the end of the option field
* can only be used as the last option.
* Only one end-of-option option can be used
TCP/IP Protocol Suite

40

Figure 8.14

Record route option

* used to record the Internet routers that handle the


datagram.
Length: Total length of the option(including code and
length fields)

Records the route a datagram takes thru routers. Can only recor
9 routers, since max size of the header is 60 bytes, 20 bytes for
base header, leaving only 40 bytes for options.
TCP/IP Protocol Suite

41

Figure 8.15

Record route concept

The Pointer field (4, then 8, then 12, then 16) is the byte
number of the first available space.

TCP/IP Protocol Suite

42

Figure 8.16

Strict source route option

For when a datagram has to follow a given, fixed route.

TCP/IP Protocol Suite

43

Figure 8.17

Strict source route concept

First hop address is here

Second hop address is here


Note that as hops are made, next hop is replaced with
address of router you just went thru
TCP/IP Protocol Suite

44

Figure 8.18

Loose source route option

Similar to fixed route - each router in the list must be visited,


but other routers can be visited too.

TCP/IP Protocol Suite

45

Figure 8.19

Timestamp option

Can be used if you want to record the time the datagram


visits each router. Time in milleseconds, Universal Time.

O-Flow bits (overflow bits) record the number of routers that coul
add their timestamp because no more fields were available.
TCP/IP Protocol Suite

46

Figure 8.20

Use of flag in timestamp

The Flag bits tell the router whether to do one of the


following operations:

-0 : add only the timestamp in the provided field


-1 : add each routers outgoing IP address and the timestamp
-3 : each router must check the given IP address with its own
incoming IP address. If matched, the router overwrites the IP
address with its outgoing IP address and adds the timestamp
TCP/IP Protocol Suite

47

Figure 8.21

TCP/IP Protocol Suite

Timestamp concept

48

Example

10
Which of the six options must be copied to each fragment?

TCP/IP Protocol Suite

49

Example

10
Which of the six options must be copied to each fragment?
Solution
We look at the first (left-most) bit of the code for each option.
a. No operation: Code is 00000001; not copied.
b. End of option: Code is 00000000; not copied.
c. Record route: Code is 00000111; not copied.
d. Strict source route: Code is 10001001; copied.
e. Loose source route: Code is 10000011; copied.
f. Timestamp: Code is 01000100; not copied.

TCP/IP Protocol Suite

50

Example

11
Which of the six options are used for datagram control and
which are used for debugging and management?

TCP/IP Protocol Suite

51

Example

11
Which of the six options are used for datagram control and
which are used for debugging and management?
Solution
We look at the second and third (left-most) bits of the code.
a. No operation: Code is 00000001; datagram control.
b. End of option: Code is 00000000; datagram control.
c. Record route: Code is 00000111; datagram control.
d. Strict source route: Code is 10001001; datagram control.
e. Loose source route: Code is 10000011; datagram control.
f. Time stamp: Code is 01000100; debugging and management
control.
TCP/IP Protocol Suite

52

8.4 CHECKSUM
The error detection method used by most TCP/IP protocols is called the
checksum. The checksum protects against the corruption that may occur
during the transmission of a packet. It is redundant information added
to the packet.
The checksum in the IP packet covers only the header, not the data.
Two reasons:
- All higher level protocols have their own checksum.
- The header of the IP packet changes with each visited router, but the
data doesnt.
The topics discussed in this section include:
Checksum Calculation at the Sender
Checksum Calculation at the Receiver
Checksum in the IP Packet
TCP/IP Protocol Suite

53

Note:
To create the checksum the sender does the following:
The packet is divided into k sections, each of n bits.
All sections are added together using 1s complement
arithmetic.
The final result is complemented to make the
checksum.
TCP/IP Protocol Suite

54

Figure 8.22

TCP/IP Protocol Suite

Checksum concept

55

Figure 8.23

TCP/IP Protocol Suite

Checksum in ones complement arithmetic

56

Example

17
Figure 8.24 shows an example of a checksum calculation for
an IP header without options. The header is divided into 16-bit
sections. All the sections are added and the sum is
complemented. The result is inserted in the checksum field.

See Next Slide

TCP/IP Protocol Suite

57

Figure 8.24

TCP/IP Protocol Suite

Example of checksum calculation in binary

58

Example

18
Let us do the same example in hexadecimal. Each row has four
hexadecimal digits. We calculate the sum first. Note that if an
addition results in more than one hexadecimal digit, the rightmost digit becomes the current-column digit and the rest are
carried to other columns. From the sum, we make the
checksum by complementing the sum. However, note that we
subtract each digit from 15 in hexadecimal arithmetic (just as
we subtract from 1 in binary arithmetic). This means the
complement of E (14) is 1 and the complement of 4 is B (11).
Figure 8.25 shows the calculation. Note that the result (8BB1)
is exactly the same as in Example 17.

See Next Slide


TCP/IP Protocol Suite

59

Figure 8.25

TCP/IP Protocol Suite

Example of checksum calculation in hexadecimal

60

Note:
Check Appendix C for a detailed
description of checksum calculation
and the handling of carries.

TCP/IP Protocol Suite

61

8.5 IP PACKAGE
We give an example of a simplified IP software package to
components and the relationships between the components.
package involves eight modules.

show
This

its
IP

The topics discussed in this section include:


Header-Adding Module
Processing Module
Queues
Routing Table
Forwarding Module
MTU Table
Fragmentation Module
Reassembly Table
Reassembly Module
TCP/IP Protocol Suite

62

Figure 8.26

TCP/IP Protocol Suite

IP components

63

Header-adding module
Receive : data, destination address
1. Encapsulate the data in an IP datagram by adding the IP
header
2. Calculate the checksum and insert it in the checksum field
3. Send the data to the corresponding input queue
4. Return

TCP/IP Protocol Suite

64

Processing module
1. Remove one datagram from one of the input queues
2. If(destination address is 127.X.Y.Z or matches one of the
local addresses (hostids))

1. Send the datagram to the reassembly module


2. Return
3. If(machine is a router)

1. Decrement TTL
4. If(TTL less than or equal to zero)

1. Discard the datagram


2. Send an ICMP error message
3. Return
5. Send the datagram to the routing module
6. Return

TCP/IP Protocol Suite

65

Fragmentation module

Receive : an IP datagram from the routing module


1. Extract the size of the datagram
2. If(size > MTU of the corresponding network)

1. If(D(do not fragment) bit is set)


1. Discard the datagram
2. Send an ICMP error message
3. Return
2. Else
1. Calculate the maximum size
2. Divide the datagram into fragments
3. Add header to each fragment
4. Add required options to each fragment
5. Send the datagrams
6. Return
3. Else

1. Send the datagram


4. Return
TCP/IP Protocol Suite

66

Reassembly table

Used by the reassembly module


Five fields
-

State(FREE or IN-USE)
Source IP address(source IP of the datagram)
Datagram ID(uniquely define a datagram)
Time-out(predetermined amount of time, in which all
fragments must arrive)
Fragments(a pointer to a linked list of fragments)

TCP/IP Protocol Suite

67

Reassembly module
Receive : an IP datagram from the processing module
1. If(offset value is zero and the M bit is 0)
1. Send the datagram to the appropriate queue
2. Return.
2. Search the reassembly table for the corresponding entry
3. If(not found)

1. Create a new entry


4. Insert the fragment at the appropriate place in the link list

1. If(all fragments have arrived)


1. Reassemble the fragments
2. Deliver the datagram to the corresponding upper layer protocol
3.Return

2. Else
1. Check the time-out
2. If(time-out expired)
1. Discard all fragments
2. Send an ICMP error message

5. Return
TCP/IP Protocol Suite

68

Vous aimerez peut-être aussi