Need for the Network Layer
The network layer is essential in solving the problem of delivering data across several links in an internetwork. It ensures host-to-host delivery of packets and manages the routing of these packets through various routers and switches, which is crucial when data needs to travel across different networks.
In an internetwork, the network layer is responsible for ensuring that the packets created by the source device are transmitted correctly to the destination device, even if they must pass through multiple intermediate networks (e.g., LANs and WANs). Without the network layer, devices would not be able to communicate beyond their local network.
Network Layer at the Source, Router, and Destination
-
Network Layer at the Source:
- The network layer at the source host is responsible for preparing a packet from the data received from other protocols (like the transport layer or application layer).
- It encapsulates the data into a packet and adds necessary routing information, such as the source IP address and the destination IP address.
- The source device checks its routing table to determine where to send the packet next. If the packet is too large, the network layer will fragment the packet into smaller units to ensure they fit the maximum size allowed by the network.
-
Network Layer at the Router:
- Routers, which operate at the network layer, receive incoming packets and consult their routing tables to determine the most appropriate next hop for the packet.
- The router may modify the packet header with new routing information, such as the address of the next hop or the interface through which the packet will be sent.
- The router then passes the packet down to the data link layer, which is responsible for transmitting the packet to the next router or destination.
-
Network Layer at the Destination:
- When the packet reaches its destination, the network layer at the destination host checks the destination IP address in the packet's header. If the address matches the host's own address, the packet is accepted.
- If the packet has been fragmented along the way, the network layer waits until all fragments have arrived. After all fragments are received, the packet is reassembled and passed up to the transport layer for further processing.
Internet as a Datagram Network
The Internet operates as a packet-switched network, meaning data is broken into smaller packets that are independently routed through the network. The Internet uses the datagram approach for packet switching.
- Datagram Approach: In this method, each packet is treated as an independent unit, and routers make routing decisions for each packet independently. Packets may take different paths to reach their destination, and they are not required to follow the same route as other packets from the same source.
This approach is different from the virtual circuit approach used in some other types of networks. In the virtual circuit approach, a predefined path is established before any data transmission begins, and all packets from a session follow the same route. In contrast, the datagram approach treats each packet separately, allowing greater flexibility and efficiency.
Internet as a Connectionless Network
The Internet's network layer follows a connectionless model, meaning that there is no need to establish a connection before data transmission begins. Each packet is routed independently of other packets, and there is no inherent relationship between them.
Connection-Oriented vs. Connectionless Service:
-
Connection-Oriented Service:
- In a connection-oriented network service, the source and destination first establish a connection before any data is sent. After the connection is established, packets can be sent one by one along the same path.
- The routing decision is made once when the connection is set up, and the network does not recalculate the route for each individual packet.
- Examples of connection-oriented services include Frame Relay and ATM (Asynchronous Transfer Mode), where a virtual circuit is established for communication.
-
Connectionless Service:
- In a connectionless service, each packet is treated independently, and there is no need for a predefined path between the sender and receiver.
- Each packet may take a different route through the network, depending on the current network conditions, which makes the network more flexible and scalable.
- The Internet employs a connectionless service at the network layer, meaning that each packet is routed independently from others. This allows the Internet to handle a large volume of traffic from a variety of sources.
Why Connectionless Service?
The decision to use a connectionless service in the Internet was driven by the diverse nature of the networks that make up the Internet. Since the Internet connects many different types of networks (e.g., LANs, WANs, wireless networks, etc.), establishing a fixed path between any source and destination beforehand is not feasible. Instead, the Internet benefits from treating each packet independently, allowing it to traverse a flexible and scalable network with no need for predefined routes.
In summary, the connectionless model is particularly suitable for the Internet due to its large scale, heterogeneity, and the need for dynamic and efficient routing of packets across many different network technologies.
IPv4 Overview
The Internet Protocol version 4 (IPv4) is the primary protocol used for the delivery of data across networks in the TCP/IP protocol suite. IPv4 operates as an unreliable, connectionless datagram protocol, which provides a best-effort delivery service. This means that IPv4 does not guarantee successful delivery, error recovery, or flow control (except for error detection in the header).
IPv4 is commonly paired with reliable protocols like TCP (Transmission Control Protocol), which handles error recovery, retransmission, and flow control. This combination ensures that even if IPv4 does not guarantee delivery, the higher-layer protocols provide the necessary reliability.
Characteristics of IPv4:
Unreliable Delivery: IPv4 is a best-effort delivery service. It does not track or confirm the delivery of data, which makes it "unreliable." If delivery is critical, other protocols like TCP are used on top of IPv4 to ensure reliability.
Connectionless: IPv4 does not establish a dedicated connection between the source and the destination before transmitting data. Each packet (called a datagram) is handled independently and can follow different paths to the destination, resulting in out-of-order delivery, loss, or corruption of packets.
Packet Switching: IPv4 operates over packet-switched networks. In packet switching, data is broken into small packets, each independently routed from source to destination. Each datagram in IPv4 can take different routes, resulting in flexibility but also potential issues with ordering or loss, which is managed by higher protocols.
IPv4 Datagram Format
IPv4 datagrams consist of two parts:
- Header (20 to 60 bytes)
- Data (variable size depending on the length of the header)
The header contains essential information needed for routing and delivery, while the data portion contains the payload (actual data from upper-layer protocols). The header is typically represented in 4-byte sections.
IPv4 Datagram Header Fields:
Version (VER): This 4-bit field indicates the version of the Internet Protocol. For IPv4, the version is 4. This helps the receiving system determine how to interpret the datagram.
Header Length (HLEN): A 4-bit field that specifies the length of the header in 4-byte words. The header can vary in size from 20 to 60 bytes, depending on the presence of options.
Type of Service (Differentiated Services): This 8-bit field is used to indicate the priority or type of service for the datagram. This field, previously known as the "Service Type," is now referred to as Differentiated Services (DiffServ). It helps in managing quality of service (QoS).
Total Length: A 16-bit field that defines the entire length of the datagram, including both the header and the data. The maximum size for the total length is 65,535 bytes. The total length helps in the calculation of the size of the data portion, as it subtracts the header length from the total length.
- Formula: Data Length = Total Length - Header Length
Identification: This 16-bit field is used for fragmentation. Each fragment of a datagram carries the same identification number, which helps the destination reassemble the fragments.
Flags: A 3-bit field used for controlling fragmentation. It indicates whether the datagram can be fragmented, and if so, whether more fragments follow.
Fragment Offset: A 13-bit field that specifies the position or offset of the fragment relative to the start of the original datagram. This helps in correctly reassembling fragmented datagrams.
Time to Live (TTL): This 8-bit field controls the lifespan of the datagram. It was initially designed to hold a timestamp but is now used to limit the number of hops a datagram can make through routers before being discarded. Each router decrements this value by 1. If TTL reaches 0, the datagram is discarded, preventing it from circulating indefinitely in case of routing errors.
-
Protocol: This 8-bit field identifies the higher-layer protocol to which the datagram’s payload should be delivered. Some common values are:
- 1: ICMP (Internet Control Message Protocol)
- 2: IGMP (Internet Group Management Protocol)
- 6: TCP (Transmission Control Protocol)
- 17: UDP (User Datagram Protocol)
Header Checksum: A 16-bit field used for error-checking the header. The checksum allows the receiver to detect any corruption in the header during transmission.
Source Address: A 32-bit field that contains the IPv4 address of the source device (the sender). This address is used by routers to forward the packet and allows the destination to know where the packet came from.
Destination Address: A 32-bit field that specifies the IPv4 address of the destination device (the receiver). This address helps routers route the datagram to its final destination.
Options (Optional): This field is optional and can vary in length. It can contain additional routing information or other control data, though in most cases, it is not used, and the field is empty.
Datagram Size Limitations
The total size of an IPv4 datagram is limited to 65,535 bytes. The Total Length field, which is 16 bits, defines this limitation. While this might seem large, physical networks may not be able to handle datagrams of this size, requiring fragmentation to fit the transmission constraints of the underlying network.
Fragmentation and Reassembly
When an IPv4 datagram is larger than the Maximum Transmission Unit (MTU) of a network (such as Ethernet), it must be fragmented. The Identification, Flags, and Fragmentation Offset fields are used during fragmentation to ensure that each fragment can be correctly reassembled by the destination host.
IPv4 Addressing
IPv4 addresses are 32-bit numerical labels assigned to each device in a network. They are typically represented in dotted decimal notation, such as 192.168.1.1. Each address consists of four octets, each representing 8 bits, allowing for over 4 billion possible unique addresses.
IPv6 Overview
IPv6 (Internet Protocol version 6) is the successor to IPv4 and was developed to address the limitations of IPv4, particularly its address space. IPv6 uses 128-bit addresses, allowing for a significantly larger address space than IPv4's 32-bit addresses.
An IPv6 datagram consists of a mandatory base header followed by the payload. The payload includes optional extension headers and the data from the upper layer. The base header is always 40 bytes in length, and the total size of the payload (including data from the upper layer and extension headers) can be up to 65,535 bytes.
IPv6 Packet Format
The IPv6 packet format is composed of:
- Base Header: Occupies 40 bytes.
- Extension Headers: Optional headers that provide additional information such as routing or security.
- Payload (Data from the Upper Layer): Contains data that comes from the transport layer, such as TCP or UDP data.
The Base Header contains the following eight fields:
Version (4 bits): This field indicates the version of the IP protocol. For IPv6, this field is set to 6.
Priority (4 bits): This field indicates the priority of the datagram in relation to network congestion. It helps determine how traffic is handled when the network is congested. It is important for quality of service (QoS) and traffic management.
Flow Label (24 bits): This 3-byte field is used to identify packets that belong to the same flow of data. A flow is typically a sequence of packets sent from a particular source to a destination, which may require special handling (e.g., for multimedia streaming). The flow label ensures that packets in the same flow are processed with special priority, if needed.
Payload Length (16 bits): This 2-byte field indicates the length of the data in the packet, excluding the base header. This is equivalent to the Total Length field in IPv4, but it does not include the header.
-
Next Header (8 bits): This field specifies the type of the next header immediately following the base header. The Next Header field can point to various optional extension headers or the header of the encapsulated data, such as TCP or UDP.
- For instance, TCP would be indicated by the value 6, while UDP would be represented by 17.
- If extension headers are used, the Next Header field will point to the type of the next extension header.
Hop Limit (8 bits): Similar to the Time to Live (TTL) field in IPv4, the hop limit field limits the number of hops (routers) a packet can make before being discarded. This prevents packets from circulating indefinitely in case of routing loops. Each router that processes the datagram decrements this field by 1. If the hop limit reaches zero, the datagram is discarded.
Source Address (128 bits): This 16-byte field identifies the source of the IPv6 datagram. It is the IPv6 address of the device that originally sent the packet.
Destination Address (128 bits): This 16-byte field contains the IPv6 address of the destination of the packet. This address could point to the final destination, or, in the case of source routing, it could point to the next hop or router in the route.
Extension Headers
IPv6 supports optional extension headers that provide additional information about the packet's handling. These headers are inserted between the base header and the upper-layer data, and they are identified through the Next Header field. Each extension header also includes a Next Header field to point to the next header in the chain. These headers are used for various purposes, such as routing, fragmentation, or security.
IPv6 Addressing
IPv6 uses 128-bit addresses, which are represented as eight groups of four hexadecimal digits separated by colons (e.g., 2001:0db8:85a3:0000:0000:8a2e:0370:7334
). This expanded address space allows for a vastly larger number of unique IP addresses compared to IPv4, ensuring that IPv6 can accommodate the growing number of devices on the internet.
IPv6 was designed to overcome the limitations of IPv4, particularly in terms of address space, and to provide a more flexible and scalable solution for internet communication. The packet format of IPv6 allows for more efficient routing, supports larger address spaces, and is capable of handling optional extension headers that provide various functionalities, such as routing, fragmentation, and security. The larger address space (128 bits) and various other improvements ensure that IPv6 will continue to support the expanding networked world.
Address Resolution Protocol (ARP)
Address Resolution Protocol (ARP) is a communication protocol used to map a known IP address to a MAC (Media Access Control) address in a local area network (LAN). It is a critical component of the TCP/IP protocol suite, operating at the network layer.
1. Overview of ARP
- Purpose: ARP is responsible for finding the MAC address corresponding to an IP address. This is essential because devices communicate at the data link layer using MAC addresses, while humans and higher-level applications rely on IP addresses.
- Scope: ARP operates within a single LAN and cannot be used to resolve addresses across different networks.
2. ARP Packet Format
An ARP packet has the following structure:
Field | Description |
---|---|
Hardware Type (HTYPE) | Specifies the type of hardware being used. For Ethernet, the value is 1. |
Protocol Type (PTYPE) | Specifies the protocol being mapped (e.g., IPv4). For IPv4, the value is 0x0800. |
Hardware Address Length (HLEN) | Length of the MAC address in bytes (typically 6 for Ethernet). |
Protocol Address Length (PLEN) | Length of the IP address in bytes (typically 4 for IPv4). |
Operation | Specifies whether the ARP packet is a request (1) or a reply (2). |
Sender Hardware Address | MAC address of the device sending the ARP packet. |
Sender Protocol Address | IP address of the device sending the ARP packet. |
Target Hardware Address | MAC address of the target device (set to 0 in a request). |
Target Protocol Address | IP address of the target device whose MAC address is being requested. |
3. ARP Workflow
The ARP process typically follows these steps:
a. ARP Request
- A device (Host A) that wants to send data to another device (Host B) knows the destination IP address but not its MAC address.
- Host A broadcasts an ARP request to all devices on the network. This packet contains:
- Host A's IP and MAC addresses.
- Host B's IP address with the MAC address set to 0 (unknown).
b. ARP Reply
- When Host B receives the ARP request and recognizes its own IP address, it sends an ARP reply directly to Host A (unicast).
- The ARP reply contains Host B's MAC address.
c. Data Transmission
- Host A receives the ARP reply, caches Host B’s MAC address in its ARP table, and uses this MAC address to communicate with Host B.
4. ARP Table
Devices maintain a cache, called the ARP table, that stores recently resolved IP-to-MAC mappings.
-
Entries:
- Dynamic Entries: Learned through ARP requests and replies.
- Static Entries: Manually configured and do not expire.
-
Commands:
- View ARP Table:
arp -a
- Add Static Entry:
arp -s <IP> <MAC>
- Delete Entry:
arp -d <IP>
Dynamic Host Configuration Protocol (DHCP)
The Dynamic Host Configuration Protocol (DHCP) is a network management protocol used to dynamically assign IP addresses and other network configuration parameters to devices (clients) on a network. This eliminates the need for manual configuration and ensures efficient use of IP addresses.
1. Overview of DHCP
- Purpose: Automatically assign IP addresses, subnet masks, gateways, and other settings to devices on a network.
- Protocol Type: Application layer protocol that operates over UDP.
-
Ports Used:
- UDP port 67 for the server.
- UDP port 68 for the client.
2. Key Features of DHCP
- Dynamic Allocation: Assigns IP addresses for a specified lease duration.
- Automatic Allocation: Assigns permanent IP addresses to clients.
- Manual Allocation: Assigns pre-determined IP addresses based on the device's MAC address (via DHCP reservations).
3. DHCP Workflow
The DHCP process is a four-step process often abbreviated as DORA:
a. Discovery
- The client broadcasts a DHCPDISCOVER message to locate DHCP servers.
- The broadcast is sent to the address 255.255.255.255 because the client does not yet have an IP address.
b. Offer
- One or more DHCP servers respond with a DHCPOFFER message, offering an IP address and configuration settings.
- The offer includes:
- IP address.
- Subnet mask.
- Lease duration.
- Gateway and DNS server addresses.
c. Request
- The client selects one offer and broadcasts a DHCPREQUEST message to inform all DHCP servers of its selection.
- This step also formally requests the offered configuration from the chosen server.
d. Acknowledgment
- The selected DHCP server confirms the assignment by sending a DHCPACK message.
- The client configures its network interface with the provided settings.
ICMP (Internet Control Message Protocol)
- Purpose: Provides error reporting and diagnostic messages in IP networks.
-
Key Features:
- Used for reporting errors (e.g., unreachable hosts or networks).
- Handles diagnostic queries (e.g.,
ping
andtraceroute
). - Works at the network layer and encapsulated in IP packets.
-
Common Message Types:
-
Echo Request/Reply: Used by
ping
to check host availability. - Destination Unreachable: Indicates that a packet cannot reach its destination.
- Time Exceeded: Sent when a packet's TTL reaches zero.
-
Echo Request/Reply: Used by
- Limitations: Cannot correct errors, only reports them.
IGMP (Internet Group Management Protocol)
- Purpose: Manages membership of devices in multicast groups for efficient multicast traffic delivery.
-
Key Features:
- Operates between hosts and multicast routers.
- Allows devices to join or leave multicast groups.
-
Common Versions:
- IGMPv1: Basic join and leave functionality.
- IGMPv2: Adds query and leave group messages for better control.
- IGMPv3: Supports source-specific multicast (SSM) for filtering multicast sources.
-
Applications:
- Used in streaming media, online gaming, and multicast-based services like IPTV.
- Limitations: Vulnerable to spoofing attacks; requires security measures like IGMP snooping.
Delivery in Networking
Direct Delivery
- Definition: The source and destination are on the same physical network (e.g., the same LAN).
-
How It Works:
- The packet is sent directly to the destination host without needing intermediate routers.
- Uses the MAC address of the destination in the data link layer.
- Example: Communication between two computers connected to the same Ethernet switch.
Indirect Delivery
- Definition: The source and destination are on different networks, requiring routers to forward the packet.
-
How It Works:
- The packet is forwarded to the router, which uses the destination IP address to determine the next hop.
- The process repeats until the packet reaches the destination network.
Forwarding
- Definition: The process of deciding which interface a packet should be sent to based on its destination address.
-
Forwarding Techniques:
- Next-Hop Forwarding: The routing table contains only the next router's address.
- Network-Specific Forwarding: Forwarding decisions are based on the destination network instead of individual hosts.
- Host-Specific Forwarding: A specific route is maintained for each destination host.
- Default Forwarding: If no specific route exists, the packet is sent to a default route.
Routing Table
- Purpose: A data table stored in routers or hosts used to determine the best path for forwarding packets.
-
Fields in a Routing Table:
- Destination: Specifies the destination network or host.
- Next Hop: Indicates the next router to which the packet should be sent.
- Metric: Represents the cost of reaching the destination (e.g., hop count, bandwidth).
- Interface: Specifies the router interface to send the packet through.
Static Routing Table
- Definition: The routes are manually entered and do not change unless manually updated.
-
Advantages:
- Simple to configure.
- No overhead for route computation.
-
Disadvantages:
- Does not adapt to network changes.
- Not scalable for large networks.
Dynamic Routing Table
- Definition: Routes are automatically updated using routing protocols.
-
Advantages:
- Adapts to network changes (e.g., link failures).
- Scalable for large networks.
-
Disadvantages:
- Adds overhead due to routing updates.
- Requires additional configuration for protocols.
Unicast Routing Protocols
Intradomain Routing
- Definition: Routing within a single autonomous system (AS).
-
Examples:
- RIP (Routing Information Protocol).
- OSPF (Open Shortest Path First).
-
Characteristics:
- Focuses on efficiency within a controlled network.
- Uses protocols like distance vector and link state routing.
Interdomain Routing
- Definition: Routing between multiple autonomous systems.
-
Examples:
- BGP (Border Gateway Protocol).
-
Characteristics:
- Handles policy-based routing.
- Prioritizes scalability and security over speed.
Distance Vector Routing
- Definition: A protocol where routers share information about the entire network periodically with their neighbors.
-
Key Features:
- Each router maintains a table of distances to every network.
- Routing updates propagate changes slowly.
- Algorithm: Bellman-Ford.
-
Advantages:
- Simple to implement.
-
Disadvantages:
- Slow convergence.
- Vulnerable to routing loops.
- Example: RIP.
Routing Information Protocol (RIP)
- Definition: A distance-vector routing protocol used in small to medium-sized networks.
-
Key Features:
- Hop count as the metric (max: 15 hops).
- Periodic updates (every 30 seconds).
-
Limitations:
- Inefficient for large networks.
- High convergence time.
Link State Routing
- Definition: A protocol where each router has a complete map of the network and calculates the shortest path.
-
Key Features:
- Uses Dijkstra’s algorithm.
- Only changes are propagated, not the full routing table.
-
Advantages:
- Faster convergence.
- More scalable than distance vector routing.
-
Disadvantages:
- More complex.
- Higher resource usage.
- Example: OSPF.
Open Shortest Path First (OSPF)
- Definition: A link-state routing protocol used in large networks.
-
Key Features:
- Hierarchical structure with areas.
- Cost as the metric, based on bandwidth.
- Supports authentication and multicast updates.
-
Advantages:
- Efficient for large networks.
- Fast convergence.
-
Disadvantages:
- Complex configuration.
- Resource-intensive.
Path Vector Routing
- Definition: A protocol that uses path information instead of metric values for routing decisions.
-
Key Features:
- Each router advertises the path it uses to reach a network.
- Avoids routing loops by analyzing the path.
-
Advantages:
- Scalable for interdomain routing.
- Supports policy-based routing.
-
Disadvantages:
- Higher resource consumption.
- Complexity in implementation.
- Example: BGP.
Border Gateway Protocol (BGP)
- Definition: The standard interdomain routing protocol for the Internet.
-
Key Features:
- Exchanges routing information between autonomous systems.
- Uses TCP for reliable updates.
- Policy-based routing with attributes like AS-path, next-hop, and MED.
-
Advantages:
- Handles large-scale networks.
- Supports various policies and load balancing.
-
Disadvantages:
- Slow convergence.
- Requires expert configuration.
Top comments (0)