Chapter 18 Introduction To Network Layer
Chapter 18 Introduction To Network Layer
• Error Control
• Flow Control
• Congestion Control
• Quality of Service
• Security
Packet Switching
• Although in data communication switching techniques are divided into two
broad categories, circuit switching and packet switching, only packet switching
is used at the network layer because the unit of data at this layer is a packet.
• Circuit switching is mostly used at the physical layer
• At the network layer, a message from the upper layer is divided into
manageable packets and each packet is sent through the network.
• The source of the message sends the packets one by one; the destination of the
message receives the packets one by one.
• The destination waits for all packets belonging to the same message to arrive
before delivering the message to the upper layer.
• The connecting devices in a packet-switched network still need to decide how
to route the packets to the final destination.
• Today, a packet-switched network can use two different approaches to route the
packets:
• Datagram Approach
• Virtual Circuit Approach
Datagram Approach: Connectionless Service
• The network layer was designed to provide a connectionless service in which the network-
layer protocol treats each packet independently, with each packet having no relationship to
any other packet
• The idea was that the network layer is only responsible for delivery of packets from the source
to the destination.
• In this approach, the packets in a message may or may not travel the same path to their
destination.
• When the network layer provides a connectionless service, each packet traveling in the
Internet is an independent entity; there is no relationship between packets belonging to the
same message.
• Each packet is routed based on the information contained in its header: source and destination
addresses.
• The router in this case routes the packet based only on the destination address.
SA DA Data SA DA Data
Virtual-Circuit Approach: Connection-Oriented Service
• In a connection-oriented service (also called virtual-circuit approach), there is a relationship
between all packets belonging to a message.
• Before all datagrams in a message can be sent, a virtual connection should be set up to define
the path for the datagrams.
• After connection setup, the datagrams can all follow the same path.
• In this type of service, not only must the packet contain the source and destination addresses, it
must also contain a flow label, a virtual circuit identifier that defines the virtual path the packet
should follow.
• Each packet is forwarded based on the label in the packet.
• To follow the idea of connection-oriented design to be used in the Internet, we assume that the
packet has a label when it reaches the router.
• To create a connection-oriented service, a three-phase process is used: setup, data transfer,
and teardown
Setup Phase: Sending request packet in a virtual-circuit network
A to B
A to B
A to B A to B
Setup Phase: Sending acknowledgments in a virtual-circuit network
Data-Transfer Phase: Flow of one packet in an established virtual circuit
Teardown Phase:
• For example, in a Fast Ethernet LAN with the transmission rate of 100
million bits per second (100 Mbps) and a packet of 10,000 bits, it takes
(10,000)/(100,000,000) = 100 microseconds for all bits of the packet to
be put on the line.
Propagation Delay
• Propagation delay is the time it takes for a bit to travel from point A to
point B in the transmission media.
• The propagation delay for a packet-switched network depends on the
propagation delay of each network (LAN or WAN).
• The propagation delay depends on the propagation speed of the media,
which is 3 X 108 meters/second in a vacuum and normally much less in
a wired medium; it also depends on the distance of the link.
• In other words, propagation delay is:
• To alleviate address depletion, two strategies were proposed and, to some extent,
implemented: subnetting and supernetting.
• In subnetting, a class A or class B block is divided into several subnets.
• Each subnet has a larger prefix length than the original network.
• For example, if a network in class A is divided into four subnets, each subnet has
a prefix of nsub = 10. At the same time, if all of the addresses in a network are not
used, subnetting allows the addresses to be divided among several organizations.
• This idea did not work because most large organizations were not happy about dividing
the block and giving some of the unused addresses to smaller organizations.
• While subnetting was devised to divide a large block into smaller ones, supernetting was
devised to combine several class C blocks into a larger block to be attractive to
organizations that need more than the 256 addresses available in a class C block.
• This idea did not work either because it makes the routing of packets more difficult.
Advantage of Classful Addressing
• Although classful addressing had several problems and became obsolete, it had one
advantage:
• Given an address, we can easily find the class of the address and, since the prefix
length for each class is fixed, we can find the prefix length immediately.
• In other words, the prefix length in classful addressing is inherent in the address;
no extra information is needed to extract the prefix and the suffix.
Solutions for Address Depletion Problem
• With the growth of the Internet, classful addressing policy led to the unnecessary rapid
depletion of IPv4 addresses.
• The solutions to address depletion:
• IPv6 = 128 bit address space. (long term solution)
• CIDR = Classless Inter Domain Routing (immediate solution)
• Private addresses and NAT (immediate solution)
Classless Addressing
• In Classless addressing the class privilege was removed from the distribution to
compensate for the address depletion
• In classless addressing, variable-length blocks are used that belong to no classes.
• We can have a block of 1 address, 2 addresses, 4 addresses and so on.
• In classless addressing, the whole address space is divided into variable length blocks.
• The prefix in an address defines the block (network); the suffix defines the node (device).
• Theoretically, we can have a block of 20, 21, 22, . . . , 232 addresses.
• One of the restrictions is that the number of addresses in a block needs to be a power of 2.
• An organization can be granted one block of addresses
• Unlike classful addressing, the prefix length in classless addressing is variable.
• We can have a prefix length that ranges from 0 to 32.
• The size of the network is inversely proportional to the length of the prefix.
• A small prefix means a larger network; a large prefix means a smaller network.
Prefix Length: Slash Notation
• The first question that we need to answer in classless addressing is how to find the prefix
length if an address is given.
• Since the prefix length is not inherent in the address, we need to separately give the length
of the prefix.
• In this case, the prefix length, n, is added to the address, separated by a slash.
• The notation is informally referred to as slash notation and formally as classless inter-
domain routing or CIDR strategy.
• An address in classless addressing does not, per se, define the block or network to which
the address belongs; we need to give the prefix length also
Extracting Information from an Address
• Given any address in the block, we normally like to know three pieces of
information about the block to which the address belongs: the number of
addresses, the first address in the block, and the last address.
• Since the value of prefix length, n, is given, we can easily find these three pieces
of information
• The number of addresses in the block is found as N = 232−n.
• To find the first address, we keep the n leftmost bits and set the (32 − n) rightmost
bits all to 0s.
• To find the last address, we keep the n leftmost bits and set the (32 − n) rightmost
bits all to 1s.
Example 18.1
A classless address is given as 167.199.170.82/27.
Find: Number of addresses in the network, first and last
addresses.
First Address:
10100111 11000111 10101010 01010010 (IP ADDRESS)
11111111 11111111 11111111 11100000 (MASK)
________________________________________
10100111 11000111 10101010 01000000 = 167.199.170. 64 (AND)
Last Address:
10100111 11000111 10101010 01010010 (IP ADDRESS)
00000000 00000000 00000000 00011111 (NOT MASK)
______________________________________
10100111 11000111 10101010 01011111 = 167.199.170. 95 (OR)
Example 18.3
In classless addressing, an address cannot per se define the block the address
belongs to. For example, the address 230.8.24.56 can belong to many blocks.
Some of them are shown below with the value of the prefix associated with that
block:
Network Address
• Given any address and the mask we can find all information about the block.
• The first address, which is also called the network address, is particularly
important because it is used in routing a packet to its destination network.
• For the moment, let us assume that an internet is made of m networks and a router
with m interfaces.
• When a packet arrives at the router from any source host, the router needs to know
to which network the packet should be sent: from which interface the packet
should be sent out.
• After the network address has been found, the router consults its forwarding table
to find the corresponding interface from which the packet should be sent out.
• The network address is actually the identifier of the network; each network is
identified by its network address.
Network address
Block Allocation
• The next issue in classless addressing is block allocation.
• The ultimate responsibility of block allocation is given to a global authority called
the Internet Corporation for Assigned Names and Numbers (ICANN).
• However, ICANN does not normally allocate addresses to individual Internet
users.
• It assigns a large block of addresses to an ISP (or a larger organization that is
considered an ISP in this case).
• For the proper operation of the CIDR, two restrictions need to be applied to the
allocated block.:
• The number of addresses in a block must be a power of 2
For example: 2, 4, 8, 16,….,256,…, 1024,….. so on
• The first address must be evenly divisible by the number of addresses.
For example: if a block contains 4 addresses, the first address must be
divisible by 4
Example 18.4
An ISP has requested a block of 1000 addresses.
• 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. Any address in the block is used to test a piece of
software in the machine
• 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:
• The block 224.0.0.0/4 is reserved for multicast addresses.
Dynamic Host Configuration Protocol (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, that actually helps
TCP/IP at the network layer.
• DHCP has found such widespread use in the Internet that it is often called a plugand- play
protocol.
• A network manager can configure DHCP to assign permanent IP addresses to the host and
routers.
• DHCP can also be configured to provide temporary, on demand, IP addresses to hosts.
• The second capability can provide a temporary IP address to a traveller to connect her
laptop to the Internet while she is staying in the hotel.
• It also allows an ISP with 1000 granted addresses to provide services to 4000 households,
assuming not more than one-forth of customers use the Internet at the same time.
• In addition to its IP address, a computer also needs to know the network prefix (or address
mask).
• Most computers also need two other pieces of information, such as the address of a default
router to be able to communicate with other networks and the address of a name server to
be able to use names instead of addresses
DHCP Message Format
• DHCP is a client-server protocol in which the client sends a request message and the server
returns a response message.
A 64-byte option field has a dual purpose: It can carry either additional
information or some specific vendor information.
DHCP Option Field
• The 64-byte option field has a dual purpose.
• It can carry either additional information or some specific vendor information.
• The server uses a number, called a magic cookie, in the format of an IP address with the
value of 99.130.83.99.
• When the client finishes reading the message, it looks for this magic cookie.
• If present, the next 60 bytes are options.
• An option is composed of three fields: a 1-byte tag field, a 1-byte length field, and a
variable-length value field.
• There are several tag fields that are mostly used by vendors.
• If the tag field is 53, the value field defines one of the 8 message types shown below:
Operation of DHCP: DHCPDISCOVER
• The DHCP server or servers (if more than one) responds with a
DHCPOFFER message in which the your address field defines the offered
IP address for the joining host and the server address field includes the IP
address of the server.
• The message also includes the lease time for which the host can keep the IP
address.
• This message is encapsulated in a user datagram with the same port
numbers, but in the reverse order.
• The user datagram in turn is encapsulated in a datagram with the server
address as the source IP address, but the destination address is a broadcast
address, in which the server allows other DHCP servers to receive the offer
and give a better offer if they can.
Operation of DHCP: DHCPREQUEST
• The joining host receives one or more offers and selects the best of them.
• The joining host then sends a DHCPREQUEST message to the server that
has given the best offer.
• The fields with known value are set.
• The message is encapsulated in a user datagram with port numbers as the
first message.
• The user datagram is encapsulated in an IP datagram with the source
address set to the new client address, but the destination address still is set
to the broadcast address to let the other servers know that their offer was
not accepted.
Operation of DHCP: DHCPACK
• The server does not send all of the information that a client may need for
joining the network.
• In the DHCPACK message, the server defines the pathname of a file in
which the client can find complete information such as the address of the
DNS server.
• The client can then use a file transfer protocol to obtain the rest of the
needed information.
Error Control
• The use of only one global address by the NAT router allows only one private-network host
to access a given external host.
• To remove this restriction, the NAT router can use a pool of global addresses. For example,
instead of using only one global address (200.24.5.8), the NAT router can use four
addresses (200.24.5.8, 200.24.5.9, 200.24.5.10, and 200.24.5.11).
• In this case, four private-network hosts can communicate with the same external host at the
same time because each pair of addresses defines a separate connection.
• However, there are still some drawbacks:
• No more than four connections can be made to the same destination.
• No private-network host can access two external server programs (e.g., HTTP and
TELNET) at the same time.
• Two private-network hosts cannot access the same external server program (e.g.,
HTTP or TELNET) at the same time.
Translation Table: Using Both IP Addresses and Port Addresses
• To allow a many-to-many relationship between private-network hosts and external server
programs, we need more information in the translation table.
• For example, suppose two hosts inside a private network with addresses 172.18.3.1 and
172.18.3.2 need to access the HTTP server on external host 25.8.3.2. If the translation table
has five columns, instead of two, that include the source and destination port addresses and
the transport-layer protocol, the ambiguity is eliminated.
• Note that when the response from HTTP comes back, the combination of source address
(25.8.3.2) and destination port address (1401) defines the private network host to which the
response should be directed.
• Note also that for this translation to work, the ephemeral port addresses (1400 and 1401)
must be unique.
Forwarding of IP Packets
• The job of the forwarding module is to search the table, row by row.
• In each row, the n leftmost bits of the destination address (prefix) are kept and the rest
of the bits (suffix) are set to 0s.
• If the resulting address (which we call the network address), matches with the address
in the first column, the information in the next two columns is extracted; otherwise the
search continues.
• Normally, the last row has a default value in the first column which indicates all
destination addresses that did not match the previous rows.
Example 18.7
Make a forwarding table for router R1 using the
configuration in Figure below
Example 18.7
Solution
Table below shows the corresponding table.
Forwarding table for router R1
Example 18.8
Instead of previous Table, we can use Table below, in
which the network address/mask is given in bits.
Forwarding table for router R1 using prefix bits
Solution
1. The first mask (/26) is applied to the destination
address. The result is 180.70.65.128, which does not
match the corresponding network address.
2. The second mask (/25) is applied to the destination
address. The result is 180.70.65.128, which matches the
corresponding network address. The next-hop address
and the interface number m0 are extracted for
forwarding the packet
Address Aggregation
• When we use classful addressing, there is only one entry in the forwarding table for
each site outside the organization.
• The entry defines the site even if that site is subnetted.
• When a packet arrives at the router, the router checks the corresponding entry and
forwards the packet accordingly.
• When we use classless addressing, it is likely that the number of forwarding table
entries will increase.
• This is because the intent of classless addressing is to divide up the whole address
space into manageable blocks.
• The increased size of the table results in an increase in the amount of time needed to
search the table.
• To alleviate the problem, the idea of address aggregation was designed.
Address aggregation
Longest Mask Matching
• What happens if one of the organizations in the previous figure is not geographically
close to the other three
• For example, if organization 4 cannot be connected to router R1 for some reason,
• can we still use the idea of address aggregation and still assign block
140.24.7.192/26 to organization 4?
• The answer is yes, because routing in classless addressing uses another principle,
longest mask matching.
• This principle states that the forwarding table is sorted from the longest mask to the
shortest mask.
• In other words, if there are three masks, /27, /26, and /24, the mask /27 must be the first
entry and /24 must be the last.
• Let us see if this principle solves the situation in which organization 4 is separated
from the other three organizations.
Longest mask matching
Hierarchical Routing
• We said that the Internet is divided into backbone and national ISPs.
• National ISPs are divided into regional ISPs, and regional ISPs are divided into local ISPs.
• If the forwarding table has a sense of hierarchy like the Internet architecture, the forwarding
table can decrease in size
• A local ISP can be assigned a single, but large, block of addresses with a certain prefix
length.
• The local ISP can divide this block into smaller blocks of different sizes, and assign these to
individual users and organizations, both large and small.
• If the block assigned to the local ISP starts with a.b.c.d/n, the ISP can create blocks starting
with e.f.g.h/m, where m may vary for each customer and is greater than n.
• The rest of the Internet does not have to be aware of this division.
• All customers of the local ISP are defined as a.b.c.d/n to the rest of the Internet.
• Every packet destined for one of the addresses in this large block is routed to the local ISP.
• There is only one entry in every router in the world for all of these customers.
• They all belong to the same group.
• Of course, inside the local ISP, the router must recognize the subblocks and route the packet
to the destined customer.
Example 18.10
As an example of hierarchical routing, let us consider Figure below. A regional ISP is
granted 16,384 addresses starting from 120.14.64.0. The regional ISP has decided to divide
this block into 4 subblocks, each with 4096 addresses. Three of these sub-blocks are
assigned to three local ISPs, the second sub-block is reserved for future use. Note that the
mask for each block is /20 because the original block with mask /18 is divided into 4 blocks.
Geographical Routing
• When the forwarding algorithm gets the destination address of the packet, it needs to
delve into the mask column.
• For each entry, it needs to apply the mask to find the destination network address.
• It then needs to check the network addresses in the table until it finds the match.
• The router then extracts the next-hop address and the interface number to be delivered
to the data-link layer.
Example 18.12
• Figure below shows a simple example of using a label to access a switching
table. Since the labels are used as the index to the table, finding the
information in the table is immediate.
Multi-Protocol Label Switching (MPLS)
• Label: This 20-bit field defines the label that is used to index the forwarding table
in the router.
• Exp: This 3-bit field is reserved for experimental purposes.
• S: The one-bit stack field defines the situation of the subheader in the stack. When
the bit is 1, it means that the header is the last one in the stack.
• TTL: This 8-bit field is similar to the TTL field in the IP datagram. Each visited
router decrements the value of this field. When it reaches zero, the packet is
discarded to prevent looping.
Hierarchical Switching
• As we may have guessed by now, the packet switches that are used
in the network layer are called routers. Routers can be configured to
act as either a datagram switch or a virtual-circuit switch.