Computer Networks - Notes on the Network Layer
Unit II: Network Layer
Application Layer
The application layer interacts with software layers like the presentation and session layers.
Data flows between the sender and receiver through these software layers.
Transport Layer
The transport layer is considered the "heart" of the OSI model, facilitating communication between software and hardware layers.
Network Layer
The network layer sits between the transport layer (software) and the data link layer (hardware) in the OSI model.
It is responsible for routing data packets from the sender to the receiver.
Functions of Network Layer
The Network Layer is the third layer of the OSI model.
It handles the service requests from the transport layer and further forwards the service request to the data link layer.
The network layer translates the logical addresses into physical addresses.
It determines the route from the source to the destination and also manages the traffic problems such as switching, routing and controls the congestion of data packets.
The main role of the network layer is to move the packets from sending host to the receiving host.
Guaranteed delivery: This layer provides the service which guarantees that the packet will arrive at its destination.
Guaranteed delivery with bounded delay: This service guarantees that the packet will be delivered within a specified host-to-host delay bound.
In-Order packets: This service ensures that the packet arrives at the destination in the order in which they are sent.
Guaranteed max jitter: This service ensures that the amount of time taken between two successive transmissions at the sender is equal to the time between their receipt at the destination.
Security services: The network layer provides security by using a session key between the source and destination host. The network layer in the source host encrypts the payloads of datagrams being sent to the destination host. The network layer in the destination host would then decrypt the payload. In such a way, the network layer maintains the data integrity and source authentication services.
Network Layer Services
Packetizing: The process of encapsulating the data received from the upper layers of the network (also called payload) in a network layer packet at the source and decapsulating the payload from the network layer packet at the destination is known as packetizing.
Routing: When a packet reaches the router's input link, the router will move the packets to the router's output link. For example, a packet from S1 to R1 must be forwarded to the next router on the path to S2.
Logical Addressing: The data link layer implements the physical addressing and network layer implements the logical addressing. Logical addressing is also used to distinguish between source and destination system. The network layer adds a header to the packet which includes the logical addresses of both the sender and the receiver.
Internetworking: This is the main role of the network layer that it provides the logical connection between different types of networks.
Fragmentation: The fragmentation is a process of breaking the packets into the smallest individual data units that travel through different networks.
Forwarding & Routing
A router forwards a packet by examining a packet's header field and then using the header field value to index into the forwarding table.
The value stored in the forwarding table corresponding to the header field value indicates the router's outgoing interface link to which the packet is to be forwarded.
Routing algorithms determine the values in forwarding table.
Routing is the process of moving data from one device to another device.
The network layer specifies some strategies which find out the best possible route. This process is referred to as routing.
Forwarding is simply defined as the action applied by each router when a packet arrives at one of its interfaces.
The process of routing involves packet forwarding from an entry interface out to an exit interface.
Network Layer Design Issues
Store and Forward packet switching:
The host sends the packet to the nearest router.
This packet is stored there until it has fully arrived once the link is fully processed by verifying the checksum
then it is forwarded to the next router till it reaches the destination.
This mechanism is called "Store and Forward packet switching."
Services provided to Transport Layer:
Through the network-transport layer interface, the network layer transfers it's services to the transport layer. But before providing these services to the transport layer following goals must be kept in mind
Offering services must not depend on router technology.
The transport layer needs to be protected from the type, number and topology of the available router.
The network addresses for the transport layer should use uniform numbering pattern also at LAN and WAN connections.
Based on the connections there are 2 types of services provided:
Connectionless – The routing and insertion of packets into subnet is done individually. No added setup is required.
Connection-Oriented - Subnet must offer reliable service and all the packets must be transmitted over a single route.
In large networks, there may be more than one paths for transmitting data from sender to receiver.
There are two popular switching techniques - circuit switching and packet switching.
Switching Techniques
Circuit Switching: When a dedicated path is established for data transmission between sender and receiver, it is called circuit switching.
There 'is a need of pre-specified route from which data will travels and no other data is permitted.
Circuits can be permanent or temporary.
Three phases
Establish a circuit
Transfer the data
Disconnect the circuit
Advantages of Circuit Switching
Once path is set up, the only delay is in data transmission speed
No problem of congestion or garbled message
Disadvantages of Circuit Switching
Long set up time is required
A request token must travel to the receiver and then acknowledged before any transmission can happen
Line may be held up for a long time
Message Switching: In message switching, the whole message is treated as a data unit and is switching / transferred in its entirety.
A switch first receives the whole message and buffers it until there are resources available to transfer it to the next hop.
There is no establishment of a dedicated path between the sender and receiver.
If the next hop is not having enough resource to accommodate large size message, the message is stored and switch waits.
The destination address is appended to the message.
It is a dynamic routing as the message is routed through the intermediate nodes based on the information available in the message.
Each and every node stores the entire message and then forward it to the next node. This type of network is known as store and forward network.
Advantages of Message switching:
Data channels are shared among the communicating devices that improve the efficiency of using available bandwidth.
Traffic congestion can be reduced because the message is temporarily stored in the nodes.
Message priority can be used to manage the network.
The size of the message which is sent over the network can be varied. Therefore, it supports the data of unlimited size.
Disadvantages of Message switching:
Every switch in transit path needs enough storage to accommodate entire message.
Because of store-and-forward technique and waits included until resources are available, message switching is very slow.
Message switching was not a solution for streaming media and real-time applications.
Packet Switching: In packet switching technique the message is sent in one go, but it is divided into smaller pieces, known as packets, and they are sent individually.
Packets are given a unique number to identify their order at the receiving end.
Every packet contains some information in its headers such as source address, destination address and
sequence number.Packets travel across the network, taking the shortest path as possible.
All the packets are reassembled at the receiving end in correct order.
If any packet is missing or corrupted, then the message will be sent to resend the message.
If the correct order of the packets is reached, then the acknowledgment message will be sent.
There are two approaches to Packet Switching:
Datagram Packet switching
Virtual Circuit Switching
Advantages of Packet Switching
Delay in delivery of packets is less, since packets are sent as soon as they are available.
Switching devices don't require massive storage, since they don't have to store the entire messages before forwarding them to the next node.
Data delivery can continue even if some parts of the network faces link failure. Packets can be routed via other paths.
It allows simultaneous usage of the same channel by multiple users.
It ensures better bandwidth usage as a number of packets from multiple sources can be transferred via the same link.
Disadvantages of Packet Switching
They are unsuitable for applications that cannot afford delays in communication like high quality voice calls.
Packet switching high installation costs.
They require complex protocols for delivery.
Network problems may introduce errors in packets, delay in delivery of packets or loss of packets. If not properly handled, this may lead to loss of critical information.
Datagram Packet Switching: It is a packet switching technology in which packet is known as a datagram, is considered as an independent entity.
Datagram Packet Switching is also known as connectionless switching.
Each packet contains the information about the destination and switch uses this information to forward the packet to the correct destination.
The packets are reassembled at the receiving end in correct order.
In Datagram Packet Switching technique, the path is not fixed.
Intermediate nodes take the routing decisions to forward the packets.
Virtual Circuit - Packet Switching: Virtual Circuit Switching is also known as connection-oriented switching.
In the case of Virtual circuit switching, a preplanned route is established before the messages are sent.
Call request and call accept packets are used to establish the connection between sender and receiver.
In this case, the path is fixed for the duration of a logical connection.
Comparison of Virtual-Circuit and Datagram
Criteria | Virtual Circuit Networks | Datagram Networks |
|---|---|---|
Connection | Prior to data transmission, a connection is established between sender and receiver. | No connection setup is required. |
Establishment | ||
Routing | Routing decisions are made once during connection setup and remain fixed throughout the duration of the connection. | Routing decisions are made independently for each packet and can vary based on network conditions. |
Flow Control | Uses explicit flow control, where the sender adjusts its rate of transmission based on feedback from the receiver. | Uses implicit flow control, where the sender assumes a certain level of available bandwidth and sends packets accordingly. |
Congestion Control | Uses end-to-end congestion control, where the sender adjusts its rate of transmission based on feedback from the network. | Uses network-assisted congestion control, where routers monitor network conditions and may drop packets or send congestion signals to the sender. |
Error Control | Provides reliable delivery of packets by detecting and retransmitting lost or corrupted packets. | Provides unreliable delivery of packets and does not guarantee delivery or correctness. |
Overhead | Requires less overhead per packet because connection setup and state maintenance are done only once. | Requires more overhead per packet because each packet contains information about its destination address and other routing information. |
Network Layer: Logical Addressing
These are 32 bits in size
Logical address is called as IP address.
These are global addresses
The Internet addresses are 32 bits in length, called as IPv4 (IP version 4) or IP address
addresses can be generated
IPv6 (IP version 6) as futuristic/new generation addresses 128 bits in size.
addresses can be generated which can accommodate future need and can address the issue of depletion of IP addresses.
IPv4 Addresses
These are unique and Universal addresses
Each address defines one and only one connection to the internet.
Two devices can never have same IP address at the same time.
An address can be assigned to a device for some time, then taken away and can be assigned to some other device.
Address space is
Notations:
Binary notation
Decimal dotted notations
IPv4: Header
IPv4 short for Internet Protocol Version 4 is the fourth version of the Internet Protocol (IP).
IP is responsible to deliver data packets from the source host to the destination host.
This delivery is solely based on the IP Addresses in the packet headers.
IPv4 is the first major version of IP.
IPv4 is a connectionless protocol for use on packet-switched networks.
IPv4 Header Fields
Version: 4-bit field indicating the IP version used (value is 4 for IPv4).
Type Of Service: 8-bit field used for Quality of Service (QoS).
Total Length: 16-bit field representing the total datagram length in bytes (header + payload).
Minimum total length = 20 bytes (20-byte header + 0 bytes data).
Maximum total length = 65535 bytes.
Header Length: 4-bit field indicating the IP header length.
The length of IP header always lies in the range- [20 bytes, 60 bytes]
Minimum length of IP header = 5 x 4 bytes = 20 bytes.
The size of Options field can go up to 40 bytes.
Maximum length of IP header = 20 bytes + 40 bytes = 60 bytes.
Header length = Header length field value x 4 bytes
If header length field = 5 (0101), then Header length = 5 x 4 = 20 bytes
If header length field = 10 (1010), then Header length = 10 x 4 = 40 bytes
If header length field = 15 (1111), then Header length = 15 x 4 = 60 bytes
Identification: 16-bit field used for identifying fragments of an original IP datagram. Each fragmented datagram is assigned the same identification number.
DF Bit: Do Not Fragment bit. If set to 1, intermediate devices are instructed not to fragment the datagram.
MF Bit: More Fragments bit. Set to 1 for all fragments except the last one, indicating more fragments are following.
Fragment Offset: 13-bit field indicating the position of a fragmented datagram in the original unfragmented IP datagram.
Fragment offset for a given fragmented datagram = Number of data bytes ahead of it in the original unfragmented datagram
Fragment offset field value = Fragment Offset / 8
Time To Live: 8-bit field indicating the maximum number of hops a datagram can take to reach the destination.
The value of TTL is decremented by 1 when:
Datagram takes a hop to any intermediate device having network layer.
Datagram takes a hop to the destination.
If the value of TTL becomes zero before reaching the destination, then datagram is discarded.
Protocol: 8-bit field indicating the protocol to which the IP datagram belongs (e.g., ICMP = 1, TCP = 6, UDP = 17).
Header Checksum: 16-bit field containing the checksum value of the entire header for error checking.
Router updates the checksum field whenever it modifies the datagram header.
Source IP Address: 32-bit field containing the logical address of the sender.
Destination IP Address: 32-bit field containing the logical address of the receiver.
Options: Variable-size field (0 to 40 bytes) used for purposes like record route, source routing, and padding.
IPv4 Addresses - Addressing
Classful addressing: Right from inception, used the concept of classes.
This architecture is called as classful addressing
The address space is divided in classes A,B,C,D,E
This is becoming obsolete, but necessary to know to understand the rational behind classless addressing.
Class | First Byte (Binary) | First Byte (Decimal) | Network Bits | Host Bits | Range of host addresses |
|---|---|---|---|---|---|
A | 0xxxxxxx | 0-127 | 8 | 24 | 1.0.0.0 to 127.255.255.255 |
B | 10xxxxxx | 128-191 | 16 | 16 | 128.0.0.0 to 191.255.255.255 |
C | 110xxxxx | 192-223 | 24 | 8 | 192.0.0.0 to 223.255.255.255 |
D | 1110xxxx | 224-239 | N/A | N/A | 224.0.0.0 to 239.255.255.255 |
E | 1111xxxx | 240-255 | N/A | N/A | 240.0.0.0 to 255.255.255.255 |
Note: | x can be either 0 or 1 |
Host ID and Net ID (Does not apply for class D and E)
Classful and Special Addressing
Class | Binary Prefix | Range | Description |
|---|---|---|---|
A | 0 | 1.0.0.0 to 127.255.255.255 | 128 networks with 16 million hosts |
B | 10 | 128.0.0.0 to 191.255.255.255 | 16,384 networks with up to 65,536 hosts |
C | 110 | 192.0.0.0 to 223.255.255.255 | 2 million networks and 256 hosts |
D | 1110 | 224.0.0.0 to 239.255.255.255 | Multicast address |
E | 1111 | 240.0.0.0 to 255.255.255.255 | Reserved for future use |
Special IP Addresses
Address | Description |
|---|---|
0.0.0.0 | Represents "This host" and indicates that the host is not connected to a TCP/IP network. Used when a host wants to obtain an IP address from a DHCP server. |
255.255.255.255 | Limited Broadcast Address. Used to send a message to every host on the current local network. |
127.0.0.0/8 (127.x.x.x) | Loopback Addresses. Used for testing the internal network connection of a host. Packets sent to a loopback address never leave the machine. |
224.0.0.0/4 | Multicast Addresses. Assigned to a group of hosts, and packets sent to a multicast address are delivered to all hosts in that group. |
Private IP Address Blocks: | |
10.0.0.0/8 | Range of private IP addresses: 10.0.0.0 to 10.255.255.255 (16,777,216 addresses). Used for internal communication within a private network. |
172.16.0.0/12 | Range of private IP addresses: 172.16.0.0 to 172.31.255.255 (1,047,584 addresses). Used for internal communication within a private network. |
192.168.0.0/16 | Range of private IP addresses: 192.168.0.0 to 192.168.255.255 (65,536 addresses). Used for internal communication within a private network. |
169.254.0.0/16 | Range of private IP addresses: 169.254.0.0 to 169.254.255.255 (65,536 addresses). |
In Each Block: There are some special addresses reserved in each block. There are two special addresses which are in each block:
Network Address
Direct Broadcast Address Network Address
As we have seen in classful and classless addressing the first address of the block is the network address itself. The first address of the block has all the suffix bits as '0'. The network address is not allocated to any of the hosts in the network.
Direct Broadcast AddressThe last address of the block is reserved as a direct broadcast address.
The direct-broadcast address has all its suffix bits as '1'.
The direct broadcast address will always be used as the destination address in IPv4 packet.
The number of networks and the number of hosts per class can be derived
by this formula:
Number of networks =
Number of Hosts/Network =When calculating hosts' IP addresses, 2 IP addresses are decreased because
they cannot be assigned to hosts.The first IP of a network is network number
The last IP is reserved for Broadcast IP.
Classes and Blocks
Class | Number of Blocks | Block Size | Application |
|---|---|---|---|
A | 128 | 16,777,216 | Unicast |
B | 16,384 | 65,536 | Unicast |
C | 2,097,152 | 256 | Unicast |
D | 1 | 268,435,456 | Multicast |
E | 1 | 268,435,456 | Reserved |
IPv4 - Classful Addressing
Address space: 4,294,967,296 addresses
Class Prefixes
Class A 0 Prefix
Class B 10 Prefix
Class C 110 Prefix
Class D 1110 Multicast addresses
Class E 1111 Reserved for future use
Class A 0 Prefix: Used for large networks, allowing for 16 million hosts in a single network.
Class B 10 Prefix: Suitable for medium-sized networks, accommodating up to 65,536 hosts per network.
Class C 110 Prefix: Designed for smaller networks, it supports up to 256 hosts within a single network.
Class D 1110 Prefix: Used for multicast groups, allowing the transmission of data to multiple hosts simultaneously.
Class E 1111 Prefix: Reserved for future use and experimental purposes, this class does not support standard host addressing.
Classless Addressing
Classless addressing, also known as Classless Inter-Domain Routing (CIDR), is an IP addressing scheme that replaces the classful addressing architecture.
It allows for more efficient allocation of IP addresses by using variable-length subnet masking (VLSM).
In classless addressing, IP addresses are represented with a prefix and a suffix, where the prefix indicates the network and the suffix indicates the host within that network.
The prefix length determines the size of the network and the number of available host addresses.
IPv6
IPv6, or Internet Protocol version 6, is the most recent version of the Internet Protocol (IP).
It is designed to solve many of the problems of the current IPv4 protocol, such as address depletion, security, and lack of quality of service (QoS).
IPv6 uses 128-bit addresses, which allows for unique addresses.
IPv6 addresses are typically written as eight groups of four hexadecimal digits, separated by colons (e.g., 2001:0db8:85a3:0000:0000:8a2e:0370:7334).
Routing Algorithms
Routing algorithms are used to determine the best path for data packets to travel from a source to a destination.
These algorithms examine network topology, traffic conditions, and routing policies to make forwarding decisions.
Distance Vector Routing:
Each router maintains a table of distances to all other routers in the network.
Routers exchange distance vectors with their neighbors to update their routing tables.
Examples include RIP (Routing Information Protocol).
Link State Routing:
Each router maintains a complete map of the network topology.
Routers flood the network with link state advertisements (LSAs) to share information about their neighbors.
Examples include OSPF (Open Shortest Path First) and IS-IS (Intermediate System to Intermediate System).
Path Vector Routing:
Similar to distance vector routing but includes path information.
Each router maintains a table of paths to all known networks.
Examples include BGP (Border Gateway Protocol).
NAT (Network Address Translation)
NAT is a technique used to map multiple private IP addresses to a single public IP address.
It allows multiple devices on a private network to share a single public IP address when communicating with the Internet.
NAT provides a layer of security by hiding the internal IP addresses of the devices on the private network.
Types of NAT:
Static NAT: Maps a single private IP address to a single public IP address.
Dynamic NAT: Maps a group of private IP addresses to a pool of public IP addresses.
Port Address Translation (PAT): Maps multiple private IP addresses to a single public IP address using different port numbers.
ICMP (Internet Control Message Protocol)
ICMP is a protocol used by network devices to send error messages and operational information.
It is used for troubleshooting and diagnostic purposes.
ICMP messages are encapsulated within IP packets and are used for various functions, such as:
Echo Request and Echo Reply (used by ping).
Destination Unreachable (indicates that a destination is unreachable).
Time Exceeded (indicates that a packet has exceeded its Time To Live (TTL) value).