Network Layer Fundamentals
The network layer is the third layer of the OSI reference model. It is mainly responsible for transferring packets between different networks and providing end-to-end communication.
1.1 Heterogeneous Internetworking: the “Translator” of the Network World
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
Heterogeneous internetworking means that the network layer can connect networks of different types, protocols, and technologies so that they can communicate with each other. Just as people from different countries need a translator to talk, different networks need the network layer to “translate”.
Why Is Heterogeneous Internetworking Needed?
Many kinds of network exist in the real world:
| Network type | Characteristics | Application scenario |
|---|---|---|
| Ethernet | Wired, high speed, low cost | Home and office LANs |
| Wi-Fi | Wireless, flexible, highly mobile | Homes and public places |
| Fiber network | Ultra-high speed, long distance, costly | Backbone networks and data centers |
| Mobile network | 4G/5G, wide coverage, mobility | Mobile internet access |
| Satellite network | Global coverage, high latency, costly | Navigation and remote areas |
These networks are like different languages that cannot talk to each other directly. Through the uniform IP protocol, the network layer makes the languages interoperable.
The IP Protocol: the “Common Language” of the Network
The role of the IP protocol is like that of a common language that lets speakers of different dialects communicate:
- 🔹 A uniform address format: every device has a unique IP address
- 🔹 A uniform data format: every network carries IP packets
- 🔹 A uniform forwarding rule: routers forward data according to the IP address
A concrete example:
- Your phone uses Wi-Fi (a wireless network)
- The server sits in a data center (a fiber network)
- The traffic crosses a backbone network (fiber plus satellite)
- They all communicate because they all use the IP protocol
Key Technologies for Heterogeneous Internetworking
1. Address translation
Different networks use different address formats:
- Ethernet: MAC address (48 bits, for example 00:1A:2B:3C:4D:5E)
- IP networks: IP address (32-bit IPv4 or 128-bit IPv6)
- Telephone networks: telephone number
The network layer performs address translation through the ARP protocol:
IP address → ARP protocol → MAC address, for example: 192.168.1.1 → query → 00:1A:2B:3C:4D:5E.
2. Data encapsulation
Different networks use different data formats, so the network layer encapsulates them uniformly:
Like a courier parcel:
- the contents are the goods (raw data)
- the outer layer is the courier box (the IP packet)
- the outer layer of that is the transport container (the Ethernet frame)
- the container changes with the transport method
3. Protocol conversion
The network layer converts between different protocols:
- TCP/IP ↔ IPX/SPX
- IPv4 ↔ IPv6
- Wired ↔ wireless
1.2 Routing and Packet Forwarding: the “Navigation System” for Packets
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
Routing is the process of choosing the best path from source to destination for a packet. It is like navigation software planning the best route for you.
How Routing Works
An analogy with navigation software:
| Navigation function | Network layer equivalent |
|---|---|
| Plan a route | The routing algorithm (RIP, OSPF) |
| Choose a road | Choosing the router path |
| Avoid congestion | Avoiding congested nodes |
| Update traffic conditions | Updating the routing table |
| Multiple routes | Multi-path routing |
The routing process:
The Packet Forwarding Mechanism
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
Packet forwarding moves a packet from one router to the next until it reaches the destination. It is like a parcel travelling through several transit stations on its way to the recipient.
A forwarding example:
Suppose you are sending a parcel from Beijing to Guangzhou:
| Node | Your computer | Beijing router | Shijiazhuang router | Wuhan router | Guangzhou server |
|---|---|---|---|---|---|
| Parcel analogy | Beijing shipping station | Shijiazhuang transit station | Wuhan transit station | — | Guangzhou receiving station |
| IP address | 192.168.1.10 | 10.1.1.1 | 10.2.2.2 | 10.3.3.3 | 172.16.1.100 |
The packet leaves your computer and passes through the Beijing, Shijiazhuang, and Wuhan routers in turn before reaching the Guangzhou server.
The forwarding procedure at each router:
- Receive the packet
- Extract the destination IP address
- Look up the routing table
- Choose the next-hop router
- Encapsulate the packet
- Send it to the next hop
The Structure of the Routing Table
A router maintains a routing table that records information about the network topology:
| Destination network | Next hop | Interface | Priority |
|---|---|---|---|
| 192.168.1.0/24 | Directly connected | eth0 | 0 |
| 10.0.0.0/8 | 10.1.1.1 | eth1 | 1 |
| 172.16.0.0/16 | 172.16.1.1 | eth2 | 2 |
| 0.0.0.0/0 | 192.168.1.1 | eth0 | 3 (default route) |
What the routing table columns mean:
- Destination network: the network address to be reached
- Next hop: the address of the next router
- Interface: the port the packet leaves through
- Priority: the entry with the higher priority is chosen when several paths exist
1.3 Congestion Control: the “Traffic Controller” of the Network
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
Congestion control is the set of mechanisms that prevent network performance from degrading under overload. It is like a traffic controller preventing congestion on the roads.
Causes of Congestion
An analogy with traffic congestion:
| Network congestion | Traffic congestion |
|---|---|
| Too many packets | Too many vehicles |
| Routers cannot keep up | Limited capacity at an intersection |
| Buffer overflow | The car park is full |
| Packet loss | Vehicles stuck in traffic |
| Increased transmission delay | Longer travel times |
How congestion shows up:
- 📉 The transmission rate drops
- 📈 The packet loss rate rises
- ⏱️ The delay increases
- 🔁 The number of retransmissions grows
Congestion Control Strategies
1. Congestion detection
Monitor the state of the network:
- router queue lengths
- packet loss rate
- average delay
- link utilization
2. Congestion avoidance
Prevent congestion before it happens:
- rate shaping: control the sending rate
- load balancing: spread traffic over several paths
- route optimization: steer traffic around congested areas
- resource reservation: reserve bandwidth for important traffic
3. Congestion recovery
Handle the aftermath of a congestion event:
- loss notification: ICMP source quench messages
- rate reduction: the sender slows down
- path switching: move to a different path
- priority scheduling: handle important data first
4. Traffic shaping
Control the traffic entering the network:
- token bucket: limit the sending rate
- leaky bucket: smooth the traffic
- Random Early Detection (RED): drop packets proactively to prevent congestion
2.1 Connectionless Service (Datagram Service)
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
The datagram service is the connectionless service offered by the network layer. Each packet is transmitted independently, like posting a letter: every letter is sent on its own, with no guarantee about order or reliability.
Characteristic Analysis
An analogy with posting letters:
| Characteristic | Letter analogy | Technical meaning |
|---|---|---|
| Connectionless | No need to confirm the recipient’s address | No connection has to be established in advance |
| Independent transmission | Every letter is sent on its own | Every packet is routed independently |
| May be lost | A letter may be lost | A packet may be lost |
| May arrive out of order | Several letters may arrive in a different order | Packets may arrive out of order |
| Simple and efficient | Posting a letter is quick and easy | The protocol is simple and the overhead is small |
How It Works
Sender:
- Prepare the packet (adding the destination IP address)
- Send it straight to the network
- Do not wait for an acknowledgment
Network:
- Every router routes independently
- Packets may take different paths
- Packets may be lost, delayed, or reordered
Receiver:
- Receive the packet
- Check whether the destination address matches
- Process the data or discard the packet
Applicable Scenarios
Suitable for real-time applications:
- 📞 Voice calls: a little packet loss does not affect call quality
- 📹 Video streaming: a small amount of data loss can be tolerated
- 🎮 Online games: real-time responsiveness matters more than reliability
- 📡 Video conferencing: real-time interaction, latency sensitive
Why is reliability not required? Real-time applications have these characteristics:
- Data is produced quickly: dozens of video frames per second
- Timeliness matters: stale data has no value
- They tolerate errors: a little packet loss does not affect the experience
Example: losing one frame of a video call is almost invisible to the eye, but waiting for a retransmission causes obvious stuttering.
2.2 Connection-Oriented Service (Virtual Circuit Service)
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
The virtual circuit service is the connection-oriented service offered by the network layer. A connection is established before data is transferred, which guarantees ordering and reliability. It is like making a phone call: dial first to establish the connection, then talk, and the voice stays continuous.
Characteristic Analysis
An analogy with making a phone call:
| Characteristic | Phone call analogy | Technical meaning |
|---|---|---|
| Connection-oriented | Dial first to establish the connection | A virtual circuit has to be set up in advance |
| Fixed path | The line stays fixed during the call | All packets follow the same path |
| Order guaranteed | The voice flows continuously | Packets arrive in order |
| Reliable transfer | Stable call quality | The data is guaranteed to be transferred correctly |
| Complex overhead | There is a dialing and hanging up procedure | The protocol is complex and the overhead is large |
How It Works
Connection establishment:
- The sender sends a call request
- The network establishes the virtual circuit (assigning a virtual circuit number)
- Every router on the path records the virtual circuit information
- The receiver confirms the connection
Data transfer:
- Every packet carries the virtual circuit number
- Routers forward based on the virtual circuit number
- All packets follow the same path
- Order and reliability are guaranteed
Connection release:
- The sender sends a release request
- The network releases the virtual circuit resources
- The routers on the path clear their entries
- The connection ends
Applicable Scenarios
Suitable for applications that need reliable transfer:
- 📁 File transfer: FTP and file downloads, where data must not be lost
- 🌐 Web browsing: HTTP and HTTPS, which need complete pages
- 📧 Mail transfer: SMTP and POP3, where message content must stay intact
- 📂 Database synchronization: data has to be exactly right
Why is reliability needed? Data transfer has these characteristics:
- The data is valuable: losing one file can be costly
- Timeliness requirements are modest: a retransmission can be waited for
- Error tolerance is low: corrupted data can cause serious problems
Example: when downloading a file, losing a single byte can make the whole file unusable, so reliable transmission is mandatory.
2.3 Comparison of the Two Services
| Characteristic | Datagram service | Virtual circuit service |
|---|---|---|
| Connection establishment | Not required | A connection must be established |
| Routing | Every packet is routed independently | All packets follow one path |
| Ordering | Not guaranteed | Arrival in order is guaranteed |
| Reliability | Not guaranteed | Reliable transfer is guaranteed |
| Failure handling | Adaptive routing | The connection must be re-established |
| Overhead | Small | Large |
| Flexibility | High | Low |
| Suitable for | Real-time applications | File transfer |
| Typical example | The IP protocol | X.25, ATM |
3.1 The IP Protocol: the Foundation of the Internet
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
The IP protocol is the core protocol of the network layer. It carries packets across the Internet and makes global interconnection possible.
Characteristics of the IP Protocol
Connectionless:
- every packet is handled independently
- no connection has to be established in advance
- as simple as posting a letter
Best effort:
- the data is delivered with the greatest effort possible
- reliability is not guaranteed
- packets may be lost, delayed, or reordered
Uniform addressing:
- every device has a unique IP address
- a globally scoped address system
- support for IPv4 and IPv6
The Structure of an IP Packet
IP packet = IP header + data portion
IP Header Structure (20-60 bytes)
The data portion carries application layer data (a TCP or UDP segment)
The key fields:
| Field | Meaning | Purpose |
|---|---|---|
| Version | The IP version number | IPv4=4, IPv6=6 |
| TTL | Time To Live | Prevents endless looping, the maximum hop count |
| Protocol | The upper layer protocol | TCP=6, UDP=17 |
| Source IP address | The sender’s address | Used for replies |
| Destination IP address | The receiver’s address | Used for routing and forwarding |
3.2 Supporting Protocols: the “Helpers” of IP
The ARP Protocol: Address Resolution
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
The ARP protocol converts an IP address into a MAC address, like a courier finding the exact door number from the recipient’s address.
How it works:
Scenario: the computer wants to send data to the server with the IP address 192.168.1.100.
- The computer knows the destination IP:
192.168.1.100 - But it does not know the MAC address (the physical address)
- It broadcasts an ARP request: “Who is 192.168.1.100? Tell me your MAC address”
- The server receives the ARP request and replies with an ARP response: “I am 192.168.1.100, and my MAC address is 00:1A:2B:3C:4D:5E”
- The computer receives the response and records the IP-to-MAC mapping
- It can then send data directly
The courier analogy:
- IP address = the recipient’s address (the name of the residential complex)
- MAC address = the exact door number (building and unit)
- The ARP protocol = the process of looking up the door number
The DHCP Protocol: Dynamic Address Assignment
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
The DHCP protocol assigns IP addresses to devices automatically, like a hotel assigning room numbers to guests.
How it works:
A device joins the network (the four-step DHCP exchange):
- The device sends a DHCP Discover: “I am new here and need an IP address”
- The DHCP server sends an Offer: “I am a DHCP server and I can offer an IP address”
- The device sends a DHCP Request: “Please give me an IP address”
- The DHCP server sends an Acknowledge: “Your IP is 192.168.1.100, with a lease of 24 hours”
- The device starts using that IP
- The DHCP server records it: “192.168.1.100 has been allocated to this device”
Benefits:
- ✅ Automatic configuration with no manual setup
- ✅ Address reuse, which raises utilization
- ✅ Central management, which avoids address conflicts
- ✅ Mobility: a device that moves to another network obtains a new address automatically
The ICMP Protocol: Network Diagnostics
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
The ICMP protocol is used for network diagnostics and error reporting, like a physical examination for the network.
Common applications:
The ping command:
ping 192.168.1.100
Purpose: test whether the network is reachable
Process: send an ICMP request and receive an ICMP response
Result: display latency, packet loss rate, and related information
The traceroute command:
traceroute www.baidu.com
Purpose: trace the path of a packet
Process: send a series of ICMP packets and record every router
Result: display all the routers traversed and the latency at each hop
4.1 Router: the “Traffic Hub” of the Network
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
A router is the core device of the network layer. It connects different networks and forwards packets, like a traffic hub that joins different roads and guides vehicles onward.
Router Functions
1. Connecting different networks:
- connecting LANs and WANs
- connecting wired and wireless networks
- connecting networks built on different technologies
2. Routing:
- maintaining the routing table
- choosing the best path
- updating routing information dynamically
3. Packet forwarding:
- receiving packets
- looking up the routing table
- sending them to the next hop
4. Other functions:
- NAT address translation
- ACL access control
- QoS quality assurance
- VPN support
How a Router Works
- Extract the destination IP address
- Look up the routing table
- Match the routing entries
- Choose the best route
- Check the TTL (decrement it by 1)
- Update the checksum
- Encapsulate it into a new frame
- Send it out of the designated interface
A routing table example:
| Destination network | Netmask | Next hop | Interface |
|---|---|---|---|
| 192.168.1.0 | 255.255.255.0 | Directly connected | eth0 |
| 10.0.0.0 | 255.0.0.0 | 10.1.1.1 | eth1 |
| 172.16.0.0 | 255.255.0.0 | 172.16.1.1 | eth2 |
| 0.0.0.0 | 0.0.0.0 | 192.168.1.1 | eth0 (default route) |
Routing matching rules:
- Longest match: choose the route with the longest (most specific) netmask
- Priority: when several routes match, choose the one with the higher priority
4.2 Layer 3 Switch: a High-Performance Router
Definition
A definition is a precise description of what a concept, a term, or an object means. Understanding definitions is the foundation of learning any field, and every concept has its own exact meaning.
A layer 3 switch combines the functions of a switch and a router and performs routing and forwarding in hardware, which makes it much faster. It is like an intelligent toll gate on a highway that identifies vehicles quickly and directs them.
Characteristics of a Layer 3 Switch
Differences from a router:
| Characteristic | Router | Layer 3 switch |
|---|---|---|
| Forwarding method | Software forwarding | Hardware forwarding |
| Forwarding speed | Relatively slow | Very fast |
| Number of interfaces | Few | Many |
| Suitable for | WAN interconnection | LAN routing |
| Price | Higher | Lower |
| Features | Rich feature set | Basic routing functions |
How it works:
The first packet:
- Software processing (like a router)
- Look up the routing table
- The hardware records the routing information
Subsequent packets:
- The hardware forwards them directly (like a switch)
- Forwarding is fast, using the hardware routing table
- No software processing is required
The defining characteristic is: “route once, switch many times”.
Example 1: The Process of Visiting a Website
Consider the network layer steps involved in loading a web page in a browser:
Your computer (192.168.1.10):
- You enter the address
www.baidu.com - DNS resolves it to an IP address:
220.181.38.148 - It builds the IP packet: source IP
192.168.1.10, destination IP220.181.38.148, with an HTTP request as the data
The local router: 4. Receives the packet 5. Looks up the routing table; the destination IP is not on the local network 6. Selects the default route and forwards it to the upstream router 7. Converts the source IP to a public IP using NAT
The ISP routers (several of them): 8. Each router looks up its routing table 9. Each router selects the next hop 10. The packet is forwarded hop by hop toward the Baidu server
The Baidu server (220.181.38.148): 11. Receives the IP packet 12. Checks that the destination IP matches 13. Extracts the HTTP request 14. Processes the request and returns the page
The return path:
15. The server builds the response packet (source IP 220.181.38.148, destination IP your public IP)
16. It returns hop by hop through the routers
17. NAT converts it back to the private IP
18. Your computer receives the response
Example 2: Interconnecting Different Networks
A home network interconnected with a corporate network:
Home network:
- Wi-Fi network:
192.168.1.0/24 - Wired network:
192.168.2.0/24 - Devices: phones, computers, televisions
Corporate network:
- Office network:
10.0.0.0/8 - Data center:
172.16.0.0/16 - Devices: servers, workstations
The interconnection process:
- The home router connects to the ISP over fiber
- The ISP connects to the corporate network over a leased line
- The IP protocol encapsulates uniformly: home Wi-Fi frame → IP packet → fiber frame → ISP routing → IP packet → leased line frame → corporate router
- Communication across the different networks becomes possible
Exercise 1
What is heterogeneous internetworking, and why is it needed?
Approach: give the definition, then the three reasons, and finish with a concrete example.
Steps:
The definition of heterogeneous internetworking: Heterogeneous internetworking means that the network layer can connect networks of different types, protocols, and technologies so that they can communicate with each other.
Why heterogeneous internetworking is needed:
-
Practical need:
- many network types exist in reality (Ethernet, Wi-Fi, fiber, 4G/5G, and so on)
- different networks use different technologies and protocols
- users need to communicate across networks
-
Technical differences:
- different networks use different address formats (MAC addresses, IP addresses, and so on)
- different networks use different frame formats
- different networks offer different transmission rates
-
Unified communication:
- the IP protocol provides a single communication standard
- it makes interconnection possible on a global scale
- it lets different networks behave like one “language”
An example:
- A phone accesses the internet over Wi-Fi and reaches a server in a data center (a fiber network).
- The data travels: Wi-Fi → router → fiber network → server.
- The network types differ, yet communication works because every network uses the IP protocol.
Answer: heterogeneous internetworking is the network layer’s ability to connect different network types so they can communicate; it is needed because networks differ in address format, frame format, and speed, and the IP protocol provides the common standard that bridges them.
Exercise 2
What is the difference between routing and packet forwarding?
Approach: define each term with its role, timing, and analogy, then state the relationship between them.
Steps:
Routing:
- Definition: choosing the best path from source to destination for a packet
- Role: deciding which path the packet should take
- Timing: the route is planned before the packet is sent
- Analogy: navigation software planning a route
Packet forwarding:
- Definition: moving a packet from one router to the next
- Role: the actual transmission of the packet
- Timing: performed during transmission
- Analogy: a parcel moving from one transit station to the next
The relationship:
- Routing: the macro-level decision (choosing the path)
- Packet forwarding: the micro-level execution (forwarding step by step)
- The result of the routing decision guides packet forwarding
A walkthrough: Routing: Beijing → Shijiazhuang → Wuhan → Guangzhou (choosing the path) Packet forwarding: the Beijing router forwards to the Shijiazhuang router (actual forwarding) the Shijiazhuang router forwards to the Wuhan router the Wuhan router forwards to the Guangzhou router
Answer: routing decides which path a packet should take, while packet forwarding is the hop-by-hop execution of that decision; the routing table produced by routing is what lets each router forward the next packet.
Exercise 3
What is the difference between the datagram service and the virtual circuit service, and what is each used for?
Approach: compare the two services on connection, routing, reliability, and overhead, then map each to its application areas.
Steps:
The main differences:
-
Connection method:
- Datagram: connectionless, no connection is established in advance
- Virtual circuit: connection-oriented, a connection is established first
-
Routing:
- Datagram: every packet is routed independently
- Virtual circuit: all packets follow the same path
-
Reliability:
- Datagram: no guarantee; packets may be lost or reordered
- Virtual circuit: reliable, arriving in order
-
Overhead:
- Datagram: small overhead, simple and efficient
- Virtual circuit: large overhead, since connections must be established and maintained
Applicable scenarios:
Datagram service:
- real-time applications: voice calls, video streaming, online games
- characteristics: strong timeliness requirements and high error tolerance
- reason: a little packet loss does not affect the experience, and latency matters more
Virtual circuit service:
- data transfer: file transfer, web browsing, mail transfer
- characteristics: the integrity and accuracy of the data matter
- reason: data loss is costly, and a retransmission can be waited for
Answer: the datagram service routes each packet independently with low overhead and suits latency-sensitive traffic, while the virtual circuit service establishes a fixed path that guarantees order and reliability and suits data that must arrive intact.
Exercise 4
What is the role of the ARP protocol? Briefly describe how it works.
Approach: state the role in one sentence, then walk through the four stages of the exchange.
Steps:
The role of the ARP protocol: The ARP protocol converts an IP address into a MAC address, which solves the mapping problem between network layer addresses and data link layer addresses.
How it works:
-
The sender sends an ARP request:
- the device knows the destination IP address
- but it does not know the corresponding MAC address
- it broadcasts an ARP request: “Who has this IP address? Tell me your MAC address”
-
The target device responds:
- the target device receives the ARP request
- it sees that its own MAC address is being queried
- it sends an ARP response: “I have this IP address, and my MAC address is XXX”
-
The mapping is recorded:
- the sender receives the ARP response
- it records the correspondence between the IP address and the MAC address
- it stores the mapping in the ARP cache
-
Data is sent using the address:
- later transmissions use the recorded MAC address directly
- no further ARP query is needed
The analogy: A courier knows the recipient’s address (the IP address) but has to find the exact door number (the MAC address), and obtains it by asking (the ARP request).
Answer: ARP maps an IP address to a MAC address through a broadcast request and a unicast response, and the result is cached so that later frames can be sent directly.
| Term | Abbreviation | Explanation |
|---|---|---|
| Network Layer | - | The third layer of the OSI model |
| Router | - | A network layer forwarding device |
| Packet | - | The protocol data unit of the network layer |
| Routing | - | Choosing the transmission path of a packet |
| Forwarding | - | Moving a packet from an input port to an output port |
| Heterogeneous Internetworking | - | Connecting networks of different types |
| Datagram Service | - | The connectionless service of the network layer |
| Virtual Circuit Service | VC | The connection-oriented service of the network layer |
| Internet Protocol | IP | The core protocol of the network layer |
| Address Resolution Protocol | ARP | Converts an IP address into a MAC address |
| Internet Control Message Protocol | ICMP | Network layer error and control messages |
| Dynamic Host Configuration Protocol | DHCP | Automatic IP address assignment |
| Congestion Control | - | Prevents the network from being overloaded |
| Layer 3 Switch | - | A switch with routing capability |
| Maximum Transmission Unit | MTU | The maximum data length in a link layer frame |
| Time To Live | TTL | The maximum hop count of a packet |
