1
Network Layer:
Introduction to Network Layer
NETWORK-LAYER SERVICES:
PACKETIZING
ROUTING AND
FORWARDING
PACKET SWITCHING
DATAGRAM APPROACH: CONNECTIONLESS SERVICE
VIRTUAL-CIRCUIT APPROACH: CONNECTION-ORIENTED SERVICE
Communication at the network layer
Packetizing
The first duty of the network layer is definitely packetizing: encapsulating the payload (data received
from upper layer) in a network-layer packet at the source and decapsulating the payload from the
network-layer packet at the destination.
Duty of the network layer is to carry a payload from the source to the destination without changing it or
using it.
Routing
The network layer is responsible for routing the packet from its source to the destination. A physical
network is a combination of networks (LANs and WANs) and routers that connect them The network
layer is responsible for finding the best one among these possible routes. The network layer needs to
have some specific strategies for defining the best route. This is done by running some routing
protocols.
Forwarding
Forwarding can be defined as the action applied by each router when a packet arrives at one of its
interfaces.
The decision-making table a router normally uses for applying this action is sometimes called the
forwarding table and sometimes the routing table.
When a router receives a packet from one of its, it needs to forward the packet to another network (in
unicast routing) or to some networks (in multicast routing).
Forwarding process
Position of network layer 6
• The network layer is responsible for the delivery of individual
packets from the source to the destination host
PACKET SWITCHING
A packet-switched network can use two different approaches to route the packets:
Datagram approach and
Virtual Circuit approach.
Forwarding Table
Virtual-Circuit Approach: Connection-Oriented Service
Forwarding Table
To create a connection-oriented service, a three-phase process is used:
•Setup
Request packet and
Acknowledgment packet.
•Data transfer and
•Teardown.
Sending request packet in a virtual-circuit network
Sending acknowledgments in a virtual-circuit network
Data-Transfer Phase
Flow of one packet in an established virtual circuit
IPv4 Addresses 14
An IP address is a 32-bits long
The IP addresses are unique and
universal
The address space of IPv4 is 232 or
4,294,967,296 (More than 4 billion)
Binary notation: 01110101 10010101
00011101 00000010
Dotted-decimal notation: 117.149.29.2
Hexadecimal notation: 80 0B 03 1F
Example 15
Change the following IP addresses from binary notation to dotted-decimal
notation.
a. 10000001 00001011 00001011 11101111
b. 11111001 10011011 11111011 00001111
• We replace each group of 8 bits with its equivalent decimal number and add
dots for separation:
a. 129.11.11.239
b. 249.155.251.15
Example 16
Change the following IP addresses from dotted-decimal notation to
binary notation.
a. 111.11.11.239
b. 221.131.27.225
• We replace each group of 8 bits with binary notation.
a. 01101111 00001011 00001011 11101111
b. 11011101 10000011 00011011 11111111
Example 17
Find the error in the following IPv4 addresses.
a. 111.56.014.239 b. 249.155.89.251.15
c. 75.67.347.17 d. 23.10010011.255.61
Solution:
a. No leading zero (014)
b. IPv4 address must be four numbers only
c. Each number must be less than or equal to 255 (347)
d. Mixture of binary notation and dotted decimal notation is not allowed.
Classful addressing 18
In classful addressing, the address space is divided into five classes: A, B, C, D, E
A new architecture, called classless addressing was introduced in the mid-1990s
Finding the address class 19
Classful Addressing: Example 20
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.
Classes and Blocks 21
In classful addressing, a large part of the available addresses were
wasted
Netid and Hostid 22
IP address in classes A, B, and C is divided into netid and hostid
Mask: Default Mask 23
The length of the netid and hostid is predetermined in classful
addressing
Default masking
CIDR (Classless Interdomain Routing) notation
19-
Subnetting 24
• Divide a large block of addresses into several contiguous groups and
assign each group to smaller networks called subnets
• Increase the number of 1s in the mask
Supernetting
Combine several class C blocks to create a larger range of addresses
Decrease the number of 1s in the mask (/24 /22 for C addresses)
19-
Address Depletion 25
The flaws in classful addressing scheme combined with the fast growth of the
Internet led to the near depletion of the available addresses. Yet the number of
devices on the Internet is much less than the 2 32 address space. We have run out
of class A and B addresses, and a class C block is too small for most midsize
organizations. One solution that has alleviated the problem is the idea of
classless addressing.
Advantage of Classful Addressing
Easy to identify the class of the address
No extra information is needed to extract the prefix and the suffix.
19-
Classless addressing 26
Addressing depletion is overcome by classless addressing
Many ISPs and service users need more addresses
Idea is to have variable-length blocks that belong to no class
Three restrictions on classless address blocks;
The addresses in a block must be contiguous, one after another
The number of addresses in a block must be a power of 2
The first address must be evenly divisible by the number of addresses
19-
Mask and Address Blocks 27
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.
The first address in the block can be found by setting the rightmost 32−n bits to 0s
The last address in the block can be found by setting the rightmost 32−n bits to 1s
The number of addresses in the block can be found by using the formula 232−n
Example: 205.16.37.39/28
The binary representation is 1100110 00010000 00100101 00100111
If we set 32−28 rightmost bits to 0, we get 11001101 00010000 00100101 00100000 205.16.37.32
(First address)
If we set 32 − 28 rightmost bits to 1, we get 11001101 00010000 00100101 00101111 205.16.37.47
(Last address)
The value of n is 28, which means that number of addresses is 232−28 or 24 or 16 Number of address.
Network Address 28
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
Hierarchy
Subnetting: (More Levels of Hierarchy)
29
30
In subnet 1: The address 17.12.14.29/27 can give us the subnet address if we use the
mask /27 because
Host: 00010001 00001100 00001110 00011101
Mask: /27
Subnet: 00010001 00001100 00001110 00000000 ➡ (17.12.14.0)
In subnet 2: The address 17.12.14.45/28 can give us the subnet address if we use the
mask /28 because
Host: 00010001 00001100 00001110 00101101
Mask: /28
Subnet: 00010001 00001100 00001110 00100000 ➡ (17.12.14.32)
In subnet 3: The address 17.12.14.50/28 can give us the subnet address if we use the
mask /28 because
Host: 00010001 00001100 00001110 00110010
Mask: /28
Subnet: 00010001 00001100 00001110 00110000 ➡ (17.12.14.48)
Address Allocation and Distribution: Example
31
• The first group has 64 customers; each needs 256 addresses.
• The second group has 128 customers; each needs 128 addresses.
• The third group has 128 customers; each needs 64 addresses.
Group 1 32
For this group, each customer needs 256 addresses. This means that 8 (log 2 256) bits
are needed to define each host. The prefix length is then 32 − 8 = 24. The addresses are
1st Customer: 190.100.0.0/24 190.100.0.255/24
2nd Customer: 190.100.1.0/24 190.100.1.255/24
...
64th Customer: 190.100.63.0/24 190.100.63.255/24
Total = 64 × 256 = 16,384
Group 2
For this group, each customer needs 128 addresses. This means that 7 (log 2 128) bits
are needed to define each host. The prefix length is then 32 − 7 = 25. The addresses are
1st Customer: 190.100.64.0/25 190.100.64.127/25
2nd Customer: 190.100.64.128/25 190.100.64.255/25
...
128th Customer: 190.100.127.128/25 190.100.127.255/25
Total = 128 × 128 = 16,384
33
Group 3
For this group, each customer needs 64 addresses. This means that 6 (log 2 64) bits are
needed to each host. The prefix length is then 32 − 6 = 26. The addresses are
1st Customer: 190.100.128.0/26 190.100.128.63/26
2nd Customer: 190.100.128.64/26 190.100.128.127/26
...
128th Customer: 190.100.159.192/26 190.100.159.255/26
Total = 128 × 64 = 8192
Number of granted addresses to the ISP: 65,536
Number of allocated addresses by the ISP: 40,960
Number of available addresses: 24,576
Special Addresses:
34
This-host Address
The only address in the block 0.0.0.0/32 is called the This-host address. It is used whenever a
host needs to send an IP datagram but it does not know its own address to use as the source
address.
Limited-broadcast Address
The only address in the block 255.255.255.255/32 is called the limited-broadcast address. It is
used whenever a router or a host needs to send/block a datagram to all devices in a network.
Loopback Address
The block 127.0.0.0/8 is called the loopback address. A packet with one of the addresses in this
block as the destination address never leaves the host; it will remain in the host. Used for testing
the computer in a host.
Private Addresses
Four blocks are assigned as private addresses: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, and
169.254.0.0/16.
Multicast Addresses
DYNAMIC HOST CONFIGURATION PROTOCOL
35
(DHCP)
Address assignment in an organization can be done automatically using the Dynamic
Host Configuration Protocol (DHCP).
DHCP is an application-layer program, using the client-server paradigm, which actually
helps TCP/IP at the network layer.
DHCP is often called a plug-and-play protocol.
A network manager can configure DHCP to assign permanent/temporary IP addresses
to the host and routers.
It also allows an ISP with one-forth of customers use the Internet at the same time.
Example 1000 granted addresses to provide services to 4000 households, assuming
not more than one-fourth user at a same time.
DHCP can be used to provide the four pieces of information to the host normally
needed:
The computer address
The prefix
The address of a router and
The IP address of a name server.
DHCP Message Format Fields:
Opcode: Operation code, request (1) or reply (2) 36
Htype: Hardware type (Ethernet, ...)
HLen: Length of hardware address
HCount: Maximum number of hops the packet can travel
Transaction ID: An integer set by the client and repeated by
the server
Time elapsed: The number of seconds since the client started
to boot
Flags: First bit defines unicast (0) or multicast (1); other 15
bits not used
Your IP address: The client IP address sent by the server
Client IP address: Set to 0 if the client does not know it
Server IP address: A broadcast IP address if client does not
know it
Gateway IP address: The address of default router
Server name: A 64-byte domain name of the server
Boot file name: A 128-byte file name holding extra information
Options: A 64-byte field with dual purpose described in text
Option Format 37
An option is composed of three fields:
•1-byte tag field,
•1-byte length field and
•Variable-Length value field.
38
DHCP Operation
FSM for the DHCP client 39
19-
Network Address Translation: NAT 40
Network Address Resolution
NAT enables a user to have a large set of addresses internally and
one address, or a small set of addresses, externally.
Range Total Addresses for private
networks
10.0.0.0 to 10.255.255.255 224
172.16.0.0 to 172.31.255.255 220
192.168.0.0 to 192.168.255.255 216
Addresses Translation 41
Address translation for source address of outgoing packet and for
destination address of incoming packet
Translation Table 42
Using (1) one IP address, (2) a pool of IP address, and (3) both IP
addresses and port numbers
19-
Five-Column Translation Table 43
19-
ISP and NAT 44
19-
FORWARDING OF IP PACKETS 45
When IP is used as a connectionless protocol,
forwarding is based on the destination address of
the IP datagram;
Similarly IP is used as a connection-oriented
protocol, forwarding is based on the label attached
to an IP datagram.
Simplified forwarding module in classless address 46
Make a forwarding
47
table for router R1
using the configuration
Show the forwarding
process if a packet
arrives at R1 in Figure
with the destination
address 180.70.65.140
The result is 180.70.65.128
Hierarchical Routing 48
49
Network Layer
Protocols
INTERNET PROTOCOL
Switching at the network layer in the Internet uses the datagram 50
approach
Communication at the network layer in the Internet is connectionless
Position of IPv4 in TCP/IP protocol suite
51
52
53
54
55
56
57
58
59
60
61
62
63