0% found this document useful (0 votes)
41 views66 pages

Chapter 04-Network Layer

This document discusses the network layer and IPv4 addressing. It provides an overview of network layer concepts like addressing, routing, and the IPv4 protocol. Key points include that IPv4 uses 32-bit addresses divided into classes, addresses are notated in dotted-decimal format, and the network layer is responsible for end-to-end delivery of packets across interconnected networks. Examples are provided for calculating network addresses and addressing blocks.

Uploaded by

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

Chapter 04-Network Layer

This document discusses the network layer and IPv4 addressing. It provides an overview of network layer concepts like addressing, routing, and the IPv4 protocol. Key points include that IPv4 uses 32-bit addresses divided into classes, addresses are notated in dotted-decimal format, and the network layer is responsible for end-to-end delivery of packets across interconnected networks. Examples are provided for calculating network addresses and addressing blocks.

Uploaded by

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

Chapter 4:

Network Layer

19.1
Outline
 Introduction
 Network layer overview
 IPv4 address
 IPv4 Protocol
 Network routing

2
Figure 1 Links between two hosts

19.3
Figure 2 Network layer in an internetwork

19.4
Figure 3 Network layer at the source, router, and destination

19.5
Figure 4 Network layer at the source, router, and destination (continued)

19.6
Note

Communication at the network layer in


the Internet is connectionless.

19.7
IPv4 ADDRESSES

An IPv4 address is a 32-bit address that uniquely and


universally defines the connection of a device (for
example, a computer or a router) to the Internet.

Topics discussed in this section:


Address Space
Notations
Classful Addressing
Classless Addressing
Network Address Translation (NAT)

19.8
Note

An IPv4 address is 32 bits long.

19.9
Note

The IPv4 addresses are unique


and universal.

19.10
Note

The address space of IPv4 is


232 or 4,294,967,296.

19.11
Figure 5 Dotted-decimal notation and binary notation for an IPv4 address

19.12
Note

Numbering systems are reviewed in


Appendix B.

19.13
Example 1

Change the following IPv4 addresses from binary


notation to dotted-decimal notation.

Solution
We replace each group of 8 bits with its equivalent
decimal number (see Appendix B) and add dots for
separation.

19.14
Note

In classful addressing, the address


space is divided into five classes:
A, B, C, D, and E.

19.15
Figure 6 Finding the classes in binary and dotted-decimal notation

19.16
Example 2

Find the class of each address.


a. 00000001 00001011 00001011 11101111
b. 11000001 10000011 00011011 11111111
c. 14.23.120.8
d. 252.5.15.111

Solution
a. The first bit is 0. This is a class A address.
b. The first 2 bits are 1; the third bit is 0. This is a class C
address.
c. The first byte is 14; the class is A.
d. The first byte is 252; the class is E.
19.17
Table 1 Number of blocks and block size in classful IPv4 addressing

19.18
Note

In classful addressing, a large part of


the available addresses were wasted.

19.19
Note

Classful addressing, which is almost


obsolete, is replaced with classless
addressing.

19.20
Note

In IPv4 addressing, a block of


addresses can be defined as
x.y.z.t /n
in which x.y.z.t defines one of the
addresses and the /n defines the mask.

19.21
Note

The first address in the block can be


found by setting the rightmost
32 − n bits to 0s.

19.22
Example 3

A block of addresses is granted to a small organization.


We know that one of the addresses is 205.16.37.39/28.
What is the first address in the block?

Solution
The binary representation of the given address is
11001101 00010000 00100101 00100111
If we set 32−28 rightmost bits to 0, we get
11001101 00010000 00100101 0010000
or
205.16.37.32.
This is actually the block shown in Figure 19.3.
19.23
Note

The last address in the block can be


found by setting the rightmost
32 − n bits to 1s.

19.24
Example 4

Find the last address for the block in Example 3.

Solution
The binary representation of the given address is
11001101 00010000 00100101 00100111
If we set 32 − 28 rightmost bits to 1, we get
11001101 00010000 00100101 00101111
or
205.16.37.47
This is actually the block shown in Figure 19.3.

19.25
Note

The number of addresses in the block


can be found by using the formula
232−n.

19.26
Example 5

Find the number of addresses in Example 3.

Solution
The value of n is 28, which means that number
of addresses is 2 32−28 or 16.

19.27
Example 6

Another way to find the first address, the last address, and
the number of addresses is to represent the mask as a 32-
bit binary (or 8-digit hexadecimal) number. This is
particularly useful when we are writing a program to find
these pieces of information. In Example 19.5 the /28 can
be represented as
11111111 11111111 11111111 11110000
(twenty-eight 1s and four 0s).

Find
a. The first address
b. The last address
c. The number of addresses.
19.28
Example 6

Solution
a. The first address can be found by ANDing the given
addresses with the mask. ANDing here is done bit by
bit. The result of ANDing 2 bits is 1 if both bits are 1s;
the result is 0 otherwise.

19.29
Example 6 (continued)

b. The last address can be found by ORing the given


addresses with the complement of the mask. ORing
here is done bit by bit. The result of ORing 2 bits is 0 if
both bits are 0s; the result is 1 otherwise. The
complement of a number is found by changing each 1
to 0 and each 0 to 1.

19.30
Example 6 (continued)

c. The number of addresses can be found by


complementing the mask, interpreting it as a decimal
number, and adding 1 to it.

19.31
Note

The first address in a block is


normally not assigned to any device;
it is used as the network address that
represents the organization
to the rest of the world.

19.32
Note

Each address in the block can be


considered as a two-level
hierarchical structure:
the leftmost n bits (prefix) define
the network;
the rightmost 32 − n bits define
the host.

19.33
Figure 6 Three-level hierarchy in an IPv4 address

19.34
Example 7

An ISP is granted a block of addresses starting with


190.100.0.0/16 (65,536 addresses). The ISP needs to
distribute these addresses to three groups of customers as
follows:
a. The first group has 64 customers; each needs 256
addresses.
b. The second group has 128 customers; each needs 128
addresses.
c. The third group has 128 customers; each needs 64
addresses.
Design the subblocks and find out how many addresses
are still available after these allocations.
19.35
Example 7 (continued)

Group 2
For this group, each customer needs 128 addresses. This
means that 7 (log2 128) bits are needed to define each
host. The prefix length is then 32 − 7 = 25. The addresses
are

19.36
Example 7 (continued)

Solution
Figure 19.9 shows the situation.
Group 1
For this group, each customer needs 256 addresses. This
means that 8 (log2 256) bits are needed to define each
host. The prefix length is then 32 − 8 = 24. The addresses
are

19.37
Example 7 (continued)

Group 2
For this group, each customer needs 128 addresses. This
means that 7 (log2 128) bits are needed to define each
host. The prefix length is then 32 − 7 = 25. The addresses
are

19.38
Example 7 (continued)
Group 3
For this group, each customer needs 64 addresses. This
means that 6 (log264) bits are needed to each host. The
prefix length is then 32 − 6 = 26. The addresses are

Number of granted addresses to the ISP: 65,536


Number of allocated addresses by the ISP: 40,960
Number of available addresses: 24,576
19.39
IPv4 Protocol

The Internet Protocol version 4 (IPv4) is the delivery


mechanism used by the TCP/IP protocols.

Topics discussed in this section:


Datagram
Fragmentation
Checksum
Options
19.40
Figure 7 Position of IPv4 in TCP/IP protocol suite

19.41
Figure 8 IPv4 datagram format Security
Strict source routi
Loose source rout
Record route
Timestamp

19.42
Figure 9 Service type or differentiated services

19.43
Note

The precedence subfield was part of


version 4, but never used.

19.44
Table 2 Types of service

19.45
Table 3 Default types of service

19.46
Table 4 Values for codepoints

19.47
Note

The total length field defines the total


length of the datagram including the
header.

19.48
Figure 10 Encapsulation of a small datagram in an Ethernet frame

19.49
Figure 11 Protocol field and encapsulated data

19.50
Table 12 Protocol values

19.51
Example 8

An IPv4 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 leftmost bits (0100)
show the version, which is correct. The next 4 bits (0010)
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.

19.52
Example 9

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

19.53
Example 10

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

19.54
Example 11

An IPv4 packet has arrived with the first few hexadecimal


digits as shown.
0x45000028000100000102 . . .
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. 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.
19.55
Figure 12 Maximum transfer unit (MTU)

19.56
Table 5 MTUs for some networks

19.57
Figure 13 Flags used in fragmentation

19.58
Figure 14 Fragmentation example

19.59
Figure15 Detailed fragmentation example

19.60
Example 10

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.

19.61
Example 11

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

19.62
Example 12

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

19.63
Example 13

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.

19.64
Example 14

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

19.65
19.66

You might also like