Sunteți pe pagina 1din 48

Network Layer:

Internet Protocol
The need for Network Layer

In a network, physical and data link layers


operate locally; they know nothing about
other layers, their task is limited to delivering
data from one node to the next (immediate)
node.
For data to be sent, through different links,
from source destination, Network Layer was
designed.
Internet Protocol
IP as a Routed Protocol

IP is a connectionless,
unreliable, best-effort
delivery protocol.
IP accepts whatever data
is passed down to it from
the upper layers and
forwards the data in the
form of IP Packets.
All the nodes are
identified using an IP
address.
Packets are delivered
from the source to the
destination using IP
address
Packet Propagation
Application protocol
IP is the highest layer protocol which
is implemented at both routers and
hosts

5
IP Service
Delivery service of IP is minimal

IP provide provides an unreliable connectionless best effort


service (also called: datagram service).
Unreliable: IP does not make an attempt to recover lost

packets
Connectionless: Each packet (datagram) is handled

independently. IP is not aware that packets between hosts


may be sent in a logical sequence
Best effort: IP does not make guarantees on the service (no

throughput guarantee, no delay guarantee,)

Consequences:
Higher layer protocols have to deal with losses or with
duplicate packets
Packets may be delivered out-of-sequence

6
Packets in IPv4 layer are known as
Datagram which consists of two parts:
a header and data (payload).
The length of the header is 20 60 bytes and
it contains essential information for routing
and packet delivery.
Position of IPv4 in TCP/IP protocol suite
IPv4 datagram format
IP Datagram Format
bit # 0 7 8 15 16 23 24 31
header
version DS ECN total length (in bytes)
length
D M
Identification 0 Fragment offset
F F
time-to-live (TTL) protocol header checksum

source IP address

destination IP address

options (0 to 40 bytes)

payload

4 bytes

20 bytes Header Size < 24 x 4 bytes = 60 bytes


20 bytes Total Length < 216 bytes = 65536 bytes
10
Fields of the IP Header

Version (4 bits): current version is 4, next version will be 6.


Header length (4 bits): length of IP header, in multiples of 4
bytes
DS/ECN field (1 byte)
This field was previously called as Type-of-Service (TOS)
field. The role of this field has been re-defined, but is
backwards compatible to TOS interpretation
Differentiated Service (DS) (6 bits):
Used to specify service level (currently not supported in
the Internet)
Explicit Congestion Notification (ECN) (2 bits):
New feedback mechanism used by TCP
11
Fields of the IP Header

Identification (16 bits): Unique identification of a datagram


from a host. Incremented whenever a datagram is transmitted

Flags (3 bits):
First bit always set to 0
DF bit (Do not fragment)
MF bit (More fragments)
Will be explained later Fragmentation

12
Fields of the IP Header

Time To Live (TTL) (1 byte):


Specifies longest paths before datagram is dropped
Role of TTL field: Ensure that packet is eventually dropped
when a routing loop occurs
Used as follows:
Sender sets the value (e.g., 64)
Each router decrements the value by 1
When the value reaches 0, the datagram is dropped

13
Fields of the IP Header

Protocol (1 byte):
Specifies the higher-layer protocol.
Used for demultiplexing to higher layers.

Header checksum (2 bytes): A simple 16-bit long checksum


which is computed for the header of the datagram.

14
15
Fields of the IP Header

Options:
Security restrictions
Record Route: each router that processes the packet adds its IP
address to the header.
Timestamp: each router that processes the packet adds its IP
address and time to the header.
(loose) Source Routing: specifies a list of routers that must be
traversed.
(strict) Source Routing: specifies a list of the only routers that
can be traversed.
Padding: Padding bytes are added to ensure that header
ends on a 4-byte boundary

16
ToS is an IP QoS (quality-of-service) mechanism, which
uses certain bits in the IP header to indicate to network
devices how packets should be treated
Maximum Transmission Unit
Maximum size of IP datagram is 65535, but the data link layer protocol generally imposes a
limit that is much smaller

For example:
Ethernet frames have a maximum payload of 1500 bytes
IP datagrams encapsulated in Ethernet frame cannot be longer than 1500 bytes

The limit on the maximum IP datagram size, imposed by the data link protocol is called
maximum transmission unit (MTU)
MTUs for various data link layers:
Ethernet: 1500 FDDI: 4352
802.3: 1492 ATM AAL5: 9180
802.5: 4464 PPP: 296

What if the size of an IP datagram exceeds the MTU?


IP datagram is fragmented into smaller units.
What if the route contains networks with different
MTUs?
18
IP Fragmentation
If IP packet is longer than the MTU,
the router breaks packet into smaller
packets
Called IP fragments
Fragments are still IP packets
Earlier in Mod A, fragmentation in TCP
MTU
IP Packet 3 2 1
IP Packets
Fragmentation
IP Fragmentation
What is Fragmented?
Only the original data field
New headers are created

MTU
IP Packet 3 2 1
IP Packets
Fragmentation
IP Fragmentation
What if the size of an IP datagram exceeds the MTU?
IP datagram is fragmented into smaller units.
What if the route contains networks with different
MTUs?
Ethernet
FDDI
Ring
Host A Router Host B

MTUs: FDDI: 4352 Ethernet: 1500


Fragmentation:
IP router splits the datagram into several datagram
Fragments are reassembled at receiver
Datagram Fragmentation
Example
Datagram Header Data (4000 octets)

Fragment 1 Header Data (1480 octets)

Fragment 2 Header Data (1480 octets)

Fragment 3 Header Data (1040 octets)

Fragment headers duplicate datagrams


header (except for FLAGS field)
Multiple Fragmentations

Original packet may be


fragmented multiple times along
its route
Source Destination
Host Host
Internet Internet
Process Process
Fragmentation
Defragmentation
Internet layer process on
destination host defragments,
restoring the original packet
IP Defragmentation only occurs
once
Source Destination
Host Host
Internet Internet
Process Process

Defragmentation
Fragmentation and IP
Fields
More Fragments field (1 bit)
1 if more fragments
0 if not
Source host internet process sets
to 0
If router fragments, sets More
Fragments field in last fragment to
0
In all other fragments, sets to 1
0 0 1 1
Original IP Packet Fragments
Identification Field
IP packet has a 16-bit Identification
field
Version Hdr Len
(4) (4)
TOS (8) Total Length in bytes (16)

Indication (16 bits) Flags (3) Fragment Offset (13)

Time to Live (8) Protocol (8) Header Checksum (16)

Source IP Address

Destination IP Address

Options (if any) PAD

Data Field
Identification Field
IP packet has a 16-bit Identification
field
Source host internet process places a
random number in the Identification
field
Different for each
Version Hdr Len
(4) (4)
TOS (8) IP packet
Total Length in bytes (16)

Indication (16 bits) Flags (3) Fragment Offset (13)

Time to Live (8) Protocol (8) Header Checksum (16)


Identification Field
IP packet has a 16-bit Identification
field
If router fragments, places the original
Identification field value in the
Identification field of each fragment

47 47 47 47
Original IP Packet Fragments
Identification Field
Purpose
Allows receiving hosts internet layer
process know what fragments belong
to each original packet
Works even if an IP packet is
fragmented several times

47 47 47 47
Original IP Packet Fragments
Fragment Offset Field

Fragment offset field (13 bits) is used to


reorder fragments with the same
Identification field
Contains the data fields starting point
(in octets) from the start of the data
field in the original IP packet
Version Hdr Len
(4) (4)
TOS (8) Total Length in bytes (16)

Indication (16 bits) Flags (3) Fragment Offset (13)


Fragment Offset Field

Receiving hosts internet layer process


assembles fragments in order of
increasing fragment offset field value
This works even if fragments arrive out of
order
Works even if fragmentation occurs
multiple times
Fragment Offset Field
730 212 0
Maximum transfer unit (MTU)

Table 20.5 MTUs for some


networks
Flags used in fragmentation

Figure 20.11 Fragmentation example


Figure 20.12 Detailed fragmentation example
Example 20.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
cannotsayiftheoriginalpacketwasfragmentedornot.A
nonfragmentedpacketisconsideredthelastfragment.
Example 20.6

A packet has arrived with an M bit value of 1. Is this the


first fragment, the last fragment, or a middle fragment?
Do we know if the packet was fragmented?

Solution
IftheMbitis1,itmeansthatthereisatleastonemore
fragment.Thisfragmentcanbethefirstoneoramiddle
one,butnotthelastone.Wedontknowifitisthefirst
one or a middle one; we need more information (the
valueofthefragmentationoffset).
Example 20.7

A packet has arrived with an M bit value of 1 and a


fragmentation offset value of 0. Is this the first fragment,
the last fragment, or a middle fragment?

Solution
BecausetheMbitis1,itiseitherthefirstfragmentora
middle one. Because the offset value is 0, it is the first
fragment.
Example 20.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.
Example 20.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 are the numbers of the first byte and the last
byte?
Solution
Thefirstbytenumberis1008=800.Thetotallengthis
100bytes,andtheheaderlengthis20bytes(54),which
meansthatthereare80bytesinthisdatagram.Ifthefirst
bytenumberis800,thelastbytenumbermustbe879.
Fragmentation: Recap

IP Fragmentation
Data field of a large IP packet is
fragmented
The fragments are sent into a
series of smaller IP packets fitting a
networks MTU
Fragmentation is done by routers
Fragmentation may be done
multiple times along the route
Defragmentation: Recap
IP Defragmentation
Defragmentation (reassembly) is done
once, by destination hosts internet
layer process
Defragmentation: Recap

All IP packets resulting from the


fragmentation of the same original IP
packet have the same Identification
field value
Destination host internet process
orders all IP packets from the same
original on the basis of their
Fragment Offset field values
More Fragments field tells whether
there are no more fragments coming
The IP Precedence field can be used to prioritize IP traffic. This is the
same as the postal system having different classes of mail such as
priority, overnight, and 2-day delivery. Routers can choose to use this
field to give preferential treatment to certain types of IP traffic.
Fields of the IP Header
Identification (16 bits): Unique
identification of a datagram from a
host. Incremented whenever a
datagram is transmitted

Flags (3 bits):
First bit always set to 0
DF bit (Do not fragment)

MF bit (More fragments)

Will be explained later Fragmentation


4500 003c 1c46 4000 4006 b1e6 ac10 0a63 ac10
0a0c
45 corresponds to the first two fields in the header ie 4

corresponds to the IP version and 5 corresponds to the header


length. Since header length is described in 4 byte words so
actual header length comes out to be 54=20 bytes.
00 corresponds to TOS or the type of service. This value of TOS

indicated normal operation.


003c corresponds to total length field of IP header. So in this

case the total length of IP packet is 60.


1c46 corresponds to the identification field.

4000 can be divided into two bytes. These two bytes (divided

into 3 bits and 13 bits respectively) correspond to the flags and


fragment offset of IP header fields.
4006 can be divided into 40 and 06. The first byte 40

corresponds to the TTL field and the byte 06 corresponds to the


protocol field of the IP header. 06 indicates that the protocol is
TCP.
be16 corresponds to the checksum which is set at the

source end (which sent the packet). Please note that as


already discussed this field will be set to zero while computing
the checksum at destination.
Example 20.1

An IPv4 packet has arrived with the first 8 bits as shown:


01000010
The receiver discards the packet. Why?

Solution
Thereisanerrorinthispacket.The4leftmostbits(0100)
showtheversion,whichiscorrect.Thenext4bits(0010)
showaninvalidheaderlength(24=8).Theminimum
numberofbytesintheheadermustbe20.Thepackethas
beencorruptedintransmission.
Example 20.2

In an IPv4 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
bytesintheheaderis84,or32bytes.Thefirst20bytes
arethebaseheader,thenext12bytesaretheoptions.
Example 20.3

In an IPv4 packet, the value of HLEN is 5, and the value


of the total length field is 0x0028. How many bytes of
data are being carried by this packet?

Solution
The HLEN value is 5, which means the total number of
bytesintheheaderis54,or20bytes(nooptions).The
total length is 40 bytes, which means the packet is
carrying20bytesofdata(4020).

20.49

S-ar putea să vă placă și