Network Layer (Layer 3)
Network Layer (Layer 3)
Role of Layer 3
Layer 3 (Network Layer) builds upon Layer 2 (Data Link Layer).
Layer 3's primary function is to move data from one location to another across different networks, such as accessing a video hosted on a remote server or using cloud services like AWS or Netflix.
Why Layer 3 is Needed
Scenario: Imagine two local area networks (LANs) geographically separated (e.g., East Coast and West Coast of the US).
Without Layer 3, these LANs are isolated; devices within each LAN can communicate, but not between LANs.
Challenge 1: Expensive Point-to-Point Links:
Directly connecting LANs with point-to-point links across large distances is costly and not scalable.
and
Challenge 2: Layer 2 Protocol Compatibility:
Layer 2 networks need to use the same protocol to communicate.
Different LANs may use different Layer 2 protocols (e.g., Ethernet, PPP, MPLS, ATM).
These protocols use different frame formats, making direct interconnection difficult.
Layer 3 as a Solution: Internetworking
Layer 3 provides a common protocol (IP) that can span multiple Layer 2 networks.
It adds the Internet Protocol (IP), providing IP addresses for devices.
These IP addresses enable communication across networks using routing.
Example scenario: When accessing a video, your device (with an IP address) communicates with the server (also with an IP address) using IP.
How Layer 3 Works
IP packets are moved from source to destination across the internet through intermediate networks.
Routers (Layer 3 devices) move packets across different networks.
They encapsulate packets inside Ethernet frames for each local network segment.
Encapsulation: Wrapping an IP packet inside an Ethernet frame for a specific part of its journey.
Encapsulation and Decapsulation
As data moves, IP packets are wrapped in frames, and these frames are stripped and replaced as the packet moves across different Layer 2 networks.
The IP packet remains constant throughout the journey, while the frame changes for each network segment.
This process allows connection to remote networks by crossing intermediate networks.
IP Packets
Packets are similar to frames; they contain data, a source address, and a destination address.
Frames have local source and destination addresses, while IP packets have source and destination addresses that can be on opposite sides of the planet.
Packets remain constant during their journey, being encapsulated within frames specific to each local network.
IP Versions
Two versions of IP in use:
IP version 4 (IPv4): has been used for decades.
IP version 6 (IPv6): which adds more scalability.
IP Packet Fields
Important fields in an IP packet include:
Source IP Address: The IP address of the device that generated the packet.
Destination IP Address: The intended destination IP address for the packet.
Protocol Field: Indicates which Layer 4 protocol is being used (e.g., ICMP, TCP, UDP).
If it contains TCP data inside a packet, this value will be six ().
For pings known as ICMP, this value will be one ().
If you're using UDP as the layer four protocol, then this value will be 17 ().
Data: The bulk of the space within a packet, generally provided from a Layer 4 protocol.
Time to Live (TTL): Defines the maximum number of hops a packet can move through to prevent infinite loops.
Summary of IP Packets
Packets contain data (usually from Layer 4 protocols), source and destination IP addresses.
Routers move packets between networks using these fields.
Packets are encapsulated in Layer 2 frames specific to each network they traverse.
A single packet may be encapsulated in numerous frames throughout its journey.
IP Version 6 (IPv6) Packets
Similar structure to IPv4 packets.
Key Differences:
Larger Addresses: IPv6 addresses are larger, allowing for more possible addresses.
Hop Limit: Similar to TTL in IPv4, controlling the maximum number of hops.