5.0 Network Layer
The Network Layer is a fundamental concept in computer networks, residing above the Data Link Layer and below the Transport Layer in the OSI model.
Layer Comparison and Relationships
Layer | Primary Focus | Scope | Key Protocols | Addressing |
---|---|---|---|---|
Data Link Layer | Frame transmission across single link | Local (point-to-point) | Ethernet, PPP | MAC addresses |
Network Layer | Packet delivery across multiple networks | End-to-end | IP, ICMP | IP addresses |
Transport Layer | Reliable/unreliable data transfer | End-to-end | TCP, UDP | Port numbers |
1. Role and Responsibilities * The primary role of the Network Layer is to get packets from a source host to a destination host. This is a crucial distinction from the Data Link Layer, which is typically concerned with transmitting frames across a single link. * It is the lowest OSI layer that has to deal with end-to-end transmission across interconnected networks. Layers above it, like the Transport Layer, also deal with end-to-end communication. * The Network Layer must cater for packets traveling across multiple networks, which may be different in technology, number, type, and topology (e.g., combining Ethernet, Token Ring, fiber optics, satellite networks). * Key design objectives for an effective Network Layer include being independent of processor/communication technology, independent of the number, type, and topology of the subnets, and providing a uniform addressing scheme for all hosts in the network.
2. Internet Protocol (IP) * IP is the main network layer protocol. It is most widely used, typically paired with TCP (Transport Control Protocol). * IP runs on all hosts and routers in the network. * It is responsible for handling the addressing and forwarding mechanisms. * IP relays data across network boundaries and delivers packets from one host to another using IP addresses.
3. IP Service Model (Focus on IPv4)
Service Characteristics Comparison
Aspect | IPv4 Characteristics | Implications |
---|---|---|
Connection Type | Connectionless (datagram-based) | No connection establishment required |
Delivery Guarantee | Best-effort (unreliable) | Packets may be lost, duplicated, delayed |
Ordering | No guarantee | Packets may arrive out of order |
Error Recovery | None at IP level | Higher layers (TCP) handle reliability |
- The service model provided by IP (specifically IPv4) is connectionless (datagram-based). This means a connection is not established beforehand; packets (datagrams) are simply sent out with destination information.
- It provides best-effort delivery, meaning it is an unreliable service.
- Due to this unreliable nature, packets may be lost, delivered out of order, duplicated, or delayed for a long time.
- Despite being unreliable, this best-effort service is still useful in many scenarios.
4. IPv4 Addressing
Address Structure and Classes
Class | First Bits | Network Bits | Host Bits | Address Range | Max Networks | Max Hosts per Network |
---|---|---|---|---|---|---|
A | 0 | 8 | 24 | 1.0.0.0 - 126.255.255.255 | 126 | 16, 777, 214 |
B | 10 | 16 | 16 | 128.0.0.0 - 191.255.255.255 | 16, 384 | 65, 534 |
C | 110 | 24 | 8 | 192.0.0.0 - 223.255.255.255 | 2, 097, 152 | 254 |
- IP provides a uniform addressing scheme for all hosts, acting as a way of naming nodes.
- IPv4 addresses are 32 bits (4 bytes) long. They are commonly written in dotted decimal notation, where each byte is represented as a decimal number between 0 and 255, separated by dots (e.g., 192.168.1.1).
- IPv4 addresses have a basic hierarchical structure, consisting of a network part and a host part. This is analogous to a postal address structure like country, city, street, and house number.
- IPv4 Address Classes (A, B, C) were historically used, where the class and the default split between network and host parts were determined by the first few bits of the address.
- Class A: First bit is 0. Network part is the first 8 bits. Host part is the remaining 24 bits.
- Class B: First two bits are 10. Network part is the first 16 bits. Host part is the remaining 16 bits.
- Class C: First three bits are 110. Network part is the first 24 bits. Host part is the remaining 8 bits.
Special Addresses
Address Type | Description | Example (Class C) | Usable for Hosts |
---|---|---|---|
Network Address | All host bits = 0 | 192.168.1.0 | No |
Broadcast Address | All host bits = 1 | 192.168.1.255 | No |
Host Addresses | Mixed host bits | 192.168.1.1 - 192.168.1.254 | Yes |
- Within any network or subnet, there are special addresses: the network address (all host bits are 0) and the broadcast address (all host bits are 1).
- These two special addresses reduce the number of usable host addresses in a network or subnet. If a network/subnet has H bits for the host part, the number of usable host addresses is 2H - 2.
- An IP address assigned to a device connected to the internet must be unique on the internet. They can be assigned dynamically (e.g., when connecting to a network like UniFi).
5. Subnetting (CIDR Basics)
Subnetting Example Calculation
Scenario: An ISP has been allocated 192.168.1.0/24 and needs to create 4 subnets.
Subnet | Network Address | Subnet Mask | CIDR | Usable Range | Broadcast |
---|---|---|---|---|---|
1 | 192.168.1.0 | 255.255.255.192 | /26 | 192.168.1.1 - 192.168.1.62 | 192.168.1.63 |
2 | 192.168.1.64 | 255.255.255.192 | /26 | 192.168.1.65 - 192.168.1.126 | 192.168.1.127 |
3 | 192.168.1.128 | 255.255.255.192 | /26 | 192.168.1.129 - 192.168.1.190 | 192.168.1.191 |
4 | 192.168.1.192 | 255.255.255.192 | /26 | 192.168.1.193 - 192.168.1.254 | 192.168.1.255 |
Calculation Process: * Original network: 192.168.1.0/24 (8 host bits) * For 4 subnets: Need 2 additional bits (2² = 4) * New subnet mask: /26 (24 + 2 = 26 network bits) * Host bits per subnet: 6 bits (32 - 26 = 6) * Hosts per subnet: 2⁶ - 2 = 62 usable addresses
Subnet Mask Formats
CIDR Notation | Dotted Decimal | Binary (last octet) | Host Bits | Max Hosts |
---|---|---|---|---|
/24 | 255.255.255.0 | 00000000 | 8 | 254 |
/25 | 255.255.255.128 | 10000000 | 7 | 126 |
/26 | 255.255.255.192 | 11000000 | 6 | 62 |
/27 | 255.255.255.224 | 11100000 | 5 | 30 |
/28 | 255.255.255.240 | 11110000 | 4 | 14 |
- Subnetting is a technique used to divide a larger network into smaller, distinct subnetworks. This is useful, for example, for an Internet Service Provider (ISP) to manage address space efficiently and distribute addresses to different customers or regions.
- Subnetting is implemented using a subnet mask. The subnet mask is a 32-bit number, often written in dotted decimal notation or using slash notation (CIDR - Classless Interdomain Routing).
- In the binary representation of a subnet mask, the bits that are part of the network/subnet address are set to 1, and the bits that are part of the host address are set to 0. The ones always fill from the left (most significant bit) to the right.
- The slash notation (e.g.,
/24
,/25
) indicates the number of bits set to 1 in the subnet mask. - To determine if a destination IP address is on the same subnet as the sending host, the host performs a bitwise AND operation between its own subnet mask and the destination IP address. If the result equals the subnet number of the sending host, the destination is on the same subnet.
6. IPv4 Header
IPv4 Header Field Analysis
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| IHL |Type of Service| Total Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identification |Flags| Fragment Offset |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Time to Live | Protocol | Header Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Destination Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Key Header Fields Comparison
Field | Size (bits) | Purpose | Key Values | Impact of Errors |
---|---|---|---|---|
Version | 4 | IP version identifier | 4 (IPv4) | Wrong protocol processing |
Header Length | 4 | Header size in 32-bit words | 5-15 (20-60 bytes) | Parsing errors |
Total Length | 16 | Entire packet size | 20-65535 bytes | Truncation/buffer issues |
TTL | 8 | Hop limit | 1-255 | Routing loops prevention |
Protocol | 8 | Upper layer protocol | 1(ICMP), 6(TCP), 17(UDP) | Wrong demultiplexing |
Header Checksum | 16 | Error detection | Calculated value | Corruption detection |
Fragmentation Control Fields
Field | Purpose | Values | Fragment Handling |
---|---|---|---|
Identification | Group fragments | 0-65535 | Same ID for all fragments of original packet |
DF Flag | Don't Fragment | 0/1 | If 1, packet must not be fragmented |
MF Flag | More Fragments | 0/1 | 1 for all fragments except last |
Fragment Offset | Position in original | 0-8191 (×8 bytes) | Reassembly order indicator |
- Every IP packet (datagram) carries an IPv4 header appended to the data payload from the upper layer. The header contains information needed to transfer the packet.
- Understanding the fields in the IPv4 header is important. Key fields include:
- Version: Indicates the IP version (e.g., 4 for IPv4). (IPv6 exists but is excluded from the exam).
- Header Length: Specifies the length of the IP header in 32-bit units. A value greater than 5 implies the presence of the optional "Options" field.
- Total Length: The total length of the IP datagram (header + data).
- Identification: A value used to identify fragments belonging to the same original datagram.
- Flags: Contains control bits related to fragmentation, including "Don't Fragment" (DF) and "More Fragments" (MF) flags. The DF flag set to 1 tells routers not to fragment the packet.
- Fragment Offset: Indicates the position of a fragment relative to the beginning of the original unfragmented datagram. It is measured in units of 8 bytes.
- Time To Live (TTL): A value that is decremented by each router (hop) the packet traverses. Its purpose is to limit the lifetime of a packet and prevent it from circulating endlessly in the network (e.g., due to routing loops). If TTL reaches zero, the packet is discarded.
- Protocol Identifier: Indicates the protocol used by the upper layer (e.g., TCP (6), UDP (17), ICMP (1)).
- Header Checksum: A checksum calculated only over the IP header. Its purpose is to detect errors in the header and ensure that routing information is correct. If due to error, the source or destination address changes, the packet would be misrouted.
- Source IP Address: The 32-bit IP address of the sending host.
- Destination IP Address: The 32-bit IP address of the intended receiving host.
- Options and Padding: Optional fields that can extend the header.
7. Fragmentation and Reassembly
Fragmentation Example
Original Packet: 3000 bytes data + 20 bytes header = 3020 bytes total MTU Constraint: 1500 bytes
Fragment | Data Size | Total Size | Identification | MF Flag | Fragment Offset | Offset (bytes) |
---|---|---|---|---|---|---|
1 | 1480 bytes | 1500 bytes | 12345 | 1 | 0 | 0 |
2 | 1480 bytes | 1500 bytes | 12345 | 1 | 185 | 1480 |
3 | 40 bytes | 60 bytes | 12345 | 0 | 370 | 2960 |
Calculation Notes: * Fragment Offset = (Byte Offset) / 8 * Fragment 1: 0 / 8 = 0 * Fragment 2: 1480 / 8 = 185 * Fragment 3: 2960 / 8 = 370
Fragmentation vs. Reassembly Comparison
Aspect | Fragmentation | Reassembly |
---|---|---|
Location | Source host or intermediate routers | Destination host only |
Trigger | Packet size > MTU | Receiving fragments |
Fields Used | ID, DF, MF, Fragment Offset | ID, MF, Fragment Offset |
Error Handling | Drop if DF=1 and size > MTU | Discard all if one fragment lost |
Performance Impact | Processing overhead | Buffer management, timeout |
- Messages may need to be divided into smaller packets (fragments) before transmission. This happens when a datagram is larger than the Maximum Transmission Unit (MTU) of the next network link it needs to traverse.
- Fragmentation typically occurs at the source host or at intermediate routers if necessary.
- The Identification, Flags (MF), and Fragment Offset fields in the IP header are used to manage fragmentation.
- The "More Fragments" (MF) flag is set to 1 for all fragments except the last one. The "Fragment Offset" indicates the position of the fragment's data within the original datagram.
- Fragments are reassembled back into the original datagram at the destination host. They are put together based on their Identification and Fragment Offset values, even if they arrive out of order.
- IP itself does not provide recovery for lost fragments. If a fragment is lost, the entire original datagram cannot be reassembled, and a higher layer protocol (like TCP) would be responsible for requesting retransmission.
- Sources generally try to avoid fragmentation due to the overhead involved. Re-fragmentation of an already fragmented packet is possible.
8. Forwarding (vs Routing)
Forwarding vs. Routing Comparison
Aspect | Forwarding | Routing |
---|---|---|
Scope | Local router action | Network-wide process |
Function | Move packet input → output port | Calculate/build forwarding tables |
Timeline | Per-packet basis | Periodic or topology-change triggered |
Data Structure | Uses existing forwarding table | Creates/updates forwarding table |
Location | Individual router | Network control plane |
Speed Requirement | Very fast (hardware-based) | Can be slower (software-based) |
Example Forwarding Table
Destination Network | Next Hop | Interface | Metric |
---|---|---|---|
192.168.1.0/24 | Direct | eth0 | 0 |
192.168.2.0/24 | 10.0.0.1 | eth1 | 1 |
0.0.0.0/0 | 10.0.0.254 | eth1 | 10 |
- Forwarding is the local action taken by a router to move a packet from an input interface to an output interface.
- A router determines the appropriate output port by looking up the destination IP address of the incoming packet in its forwarding table.
- (While related, the process of creating or calculating these forwarding/routing tables is called Routing, which is an excluded topic).
Concept Integration and Relationships
Network Layer Process Flow
Source Host Router Destination Host
| | |
1. Create IP packet 2. Receive packet 6. Receive packet
- Add IP header - Check TTL - Verify header
- Fragment if needed - Decrement TTL - Reassemble fragments
| - Check destination - Extract payload
2. Send to router - Lookup forwarding table |
| - Forward to next hop 7. Deliver to upper layer
| | |
+------ Network Path -------+ |
Common Calculation Types
1. Address Class Identification * Given: 172.16.5.10 * Binary: 10101100.00010000.00000101.00001010 * First two bits: 10 → Class B
2. Subnetting Calculations * Network: 192.168.1.0/24, need 6 subnets * Required subnet bits: ceil(log₂(6)) = 3 bits * New mask: /27 (24 + 3) * Hosts per subnet: 2⁵ - 2 = 30
3. Fragmentation Calculations * Original: 4000 bytes, MTU: 1500 bytes * Fragments needed: ceil(4000/1480) = 3 * Fragment offsets: 0, 185, 370
These notes cover the examinable aspects of the Network Layer and IP based on the provided sources and your list of exclusions. Remember to provide clear explanations and justifications for your answers in the exam.