TCP/IP Network Layer
Modes of Data Transfer
Circuit Switching
- Connection-oriented: Establishes a dedicated communication path (circuit) between two nodes before transmitting data
- Data is transmitted in a **continuous **stream with the same path
- NEVER implemented at network layer
- E.g. early telephone systems
Packet Switching
- Connectionless: No connection is established when data is transmitted
- Data is fragmented into smaller, more manageable chunks called packets
- Packets are individually addressed and sent to intended destination
- Receiving computer waits for all packets and reassembles packets into original message before delivering message to upper level
- Network layer in the Internet is packet-switched, regardless of connection-oriented or connectionless transport methods (TCP/UDP)
Routing of Packets
- Packet Creation: Data is encapsulated into an IP packet, where IP header contains source and destination IP address
- Routing Decision: Consult routing table → if destination is on same local network, send packet directly (direct delivery) → else forwards the packet to default gateway usually a router (indirect delivery)
- Size Check: If size of data > max size of data carried in frame (Maximum Transmission Unit MTU), packet is fragmented into smaller units
- Router Processing: the header of each packet is validated and the routing table is consulted to determine the next hop to send the packet toward the destination.
- Destination Processing: At destination, the header of the packet is validated, data is extracted from each fragment and stored.
- Reassembly Processing: When all fragments have arrived, data is reassembled and delivered to transport layer
- Reassembly Timer: if timer expired, all data fragments destroyed and datagram needs to be resent
Advantages
| Circuit Switching | Packet Switching |
|---|---|
| Provides a consistent and reliable connection with a fixed bandwidth | More efficient use of network resources since packets can be routed based on current network load |
| Data arrives in order and does not need to be reassembled | More secure as it is harder to intercept data since different packets can take different paths to destination |
Disadvantage
- Packet switching requires more time for reassembly at the destination device as packets may arrive in random order
- To handle this, a sequential number is attached to each packet, and efficient algorithms are used to sort the packets into the original order
Protocol
Definition
A set of rules, standards, or procedures that govern how data is transmitted, received and interpreted between devices in a communication network
Protocol defines format and order of messages exchanged between sender and receiver, and decides on the actions to be taken after messages are sent/received
Features
- Standardised to ensure compatibility and interoperability between different systems, devices or software
- Define how data is formatted and organised during transmission
- Specify how devices initiate, maintain and terminate communication
- Detection and correction of errors
Internet Protocol (IP)
End-to-End Protocol
- **Source **and destination IP addresses are placed in IP header as the packet moves down the TCP/IP stack
- Network layer checks if destination is on same local network or different network by comparing destination IP address with subnet mask to source IP address
- If destination is on the same subnet, packet is sent to destination (direct delivery)
- Else, packet is sent via default gateway to reach correct network (indirect delivery)
- If size of data > max size of data carried in frame (Maximum Transmission Unit MTU), packet is fragmented into smaller units before being passed on
- MAC address of next destination device (host/router) is obtained before passing packet to data link layer
- MAC address resolution uses destination IP address using ARP
IPv4 Address
Definition
IPv4: 32 bit, logical address
2 parts: prefix defines the network, suffix defines host
Class A
Network Portion: 8 bits (first octet)
- First bit (from the left) is always 02
- 2^7 or 128 possible network numbers
- 0.0.0.0 is reserved for default route or special addressing
- 127.0.0.0 is reserved and used for** loopback **
- n usable addresses: 128 - 2 = 126
Host Portion: 24 bits
- 2^24 possible combinations
- All host bits are 0 for **network **address e.g. 10.0.0.0
- All host bits are 1 for **broadcast **address e.g. 10.255.255.255
- n usable addresses: 2^24 - 2
Subnet Mask
- 255.0.0.0
Class B
Network portion: 16 bits
- First 2 bits (from the left) is always 102
- Usable network numbers is 2
Host portion: 16 bits
- Possible combinations: 2
- All host bits are 0 for **network **address e.g. 172.16.0.0
- All host bits are 1 for **broadcast **address e.g. 172.16.255.255
- Usable host addresses 2^16 - 2
Subnet Mask
- 255.255.0.0
Class C
Network portion: 24 bits
- First 3 bits (from the left) always 1102
- Usable network numbers is 2
Host portion: 8 bits
- 2^8 combinations
- All host bits are 0: **network **address e..g 192.168.1.0
- All host bits are 1: **broadcast **address e.g. 192.168.1.255
Subnet Mask
- 255.255.255.0
Class D
- First 4 bits (from the left) is always 11102
- 224.0.0.0 to 239.255.255.255
- Used for multicasting - send data to selected group of devices
- Not used for regular host address
- For video conferencing, streaming media, routing
Class E
- First 4 bits (from the left) is always 11112
- 240.0.0.0 to 255.255.255.255
- Not used
- 255.255.255.255 is a limited broadcast address to send to all hosts on local network
Types of Addresses
Network Address
- Identifies entire network segment and is not assigned to any device
- Used by routers/devices to determine where to route packets (routing table)
- First address in any subnet
Broadcast Address
- Send a message to all hosts on the network at once
- Last address in subnet
Multicasting
- Send data to a selected group (multicast group) of devices
Broadcast vs Multicast
- Broadcast sends data to every device on the network
- Multicast sends data to a specific group of devices on the network (multicast group)
Classful Addressing Scheme
- netid: Defines network (n bits)
- hostid: Defines particular host connected to the network (32-n) bits
- Given any IP address, we are able to find:
- Class of IP address and the value of n
- Number of address in the block N = 2
- First address: keep n leftmost bits and set (32-n) rightmost bits to all 0s
- Last address: keep n leftmost bits and set (32-n) rightmost bits to all 1s
Finding Network Address
Steps
- Find the class of IP address
- Find network mask of class
- Use logical AND to find network address
Example
- 201.24.67.32
- Find class of IP address: Class C
- Network mask of class B is 255.255.255.0
- Network address is 201.24.67.32 AND 255.255.255.0 -> 201.24.67.0
Limitations
- IP addresses in fixed sizes (class A to C) either too large or too small for most organisations → IP address wastage and issues with scaling
- Routing tables grew large and inefficient
- Rapid IPv4 exhaustion: classful structure wasted address space, speeds up exhaustion
- Not flexible, cannot tailor address block size to network size
Overcoming limitations
- Subnetting
- Dividing larger networks into smaller, more manageable subnetworks
- resolves issue of insufficient network addresses in classful addressing scheme, without abandoning classful addressing scheme
- Single network prefix to be used for multiple networks
- Organise networks and reduce broadcast traffic
- Variable length subnet masking (VLSM)
- Network address translation (NAT)
- Private IP address range
- Classless inter-domain routing
- Transition to IPv6 (Long term solution)
IPv6 Address
- 128 bit logical address
- Written in hexadecimal
Zero Compression of IPv6 addresses

IPv4 vs IPv6

IPv6 Address Types

Address Resolution Protocol (ARP)
- Map between logical protocol address (IP address) and hardware address (MAC address)
- Steps
- Look in ARP cache
- If found, no future resolution → IP-hardware address is stored in ARP cache for 2 min (max 10 min)
- If not found, ARP request broadcast is initiated → All nodes in local network receive copy of ARP request, destination node that has the IP address contained in destination protocol address responds with its hardware address
Network Address Translation (NAT)
- Method used in routers to translate private IP addresses used inside a local network into public addresses used on the internet and vice versa.
- Enables multiple devices on a private network to share one public IP address
Classless Inter-Domain Relationship (CIDR)

- CIDR addressing still represents IP addresses in the dotted decimal notation but highlights the network portion with a slash followed by a number
- Eg. 167.199.170.82/27 where 27 indicates the prefix length
- The number after the slash is the number of bits that represent the network portion of the IP address
Network Devices
Hub
- Hardware device that operates at the physical layer (Layer 1) of the OSI model and connects multiple devices in a local area network (LAN)
- Receives incoming data signals on one port and **broadcasts **them to all other ports, regardless of the destination
- Hubs do not filter traffic or use any addressing, resulting in shared bandwidth and potential data collisions
Switch
- Networking device that operates at the data link layer (Layer 2) of the OSI model
- It connects devices within a LAN and uses MAC addresses to forward data from sender to the intended recipient port, reducing unnecessary traffic
- Switches support full-duplex communication, and each connected device has a dedicated collision domain, improving network efficiency and performance
Router
- Networking device that operates at the network layer (Layer 3) of the OSI model
- It connects multiple networks together (e.g. LAN to WAN) and forwards data packets based on IP addresses
- Routers determine the most efficient path for data transmission, manage traffic between networks, and often provide additional functions
- Functions include Network Address Translation (NAT), Dynamic Host Configuration Protocol (DHCP), and firewall capabilities
Summary

Checksum
Definition
- Error detection method used by most TCP/IP protocols for redundancy
- Protects against the corruption that may occur during the transmission of a packet
- Checksum is calculated at the sender and the value obtained is sent with the packet
- Receiver repeats the same calculation on the whole packet including the checksum
- If the result is correct, the packet is accepted, otherwise it is rejected
Steps

- Checksum calculation at the sender:
- Packet is divided into k sections of n bits each.
- All sections are added together using one’s complement arithmetic
- Final result is complemented to make the checksum
- Checksum calculation at the receiver:
- Packet is divided into k sections of n bits each
- All sections are added together using one’s complement arithmetic
- Result is complemented
- If final result is 0, the packet is accepted, otherwise rejected
Binary Addition

Complement Arithmetic
- Similarly to normal binary addition
- When there’s a carry out of the most significant bit (MSB), the carry is wrapped around and added back into the least significant bit (LSB)
- E.g. 1111 1111 1111 1111 + 0000 0000 0000 0001 = 1 000 000 000 000
- 1 0000 0000 0000 0000 is 17 bits, which is an overflow, meaning that the carry bit is wrapped around to LSB to become 0000 0000 0000 0001
- The complement would be 0000 0000 0000 0001 AND 0000 0000 0000 0000 = 1111 1111 1111 1110
IP Header
- Checksum in IP covers only the header and not the data
- All higher-level protocols that encapsulate data in the IP datagram have a checksum field that covers the whole packet
- Checksum for IP datagram does not have to check encapsulated data
- Header of the IP packet changes with each visited router, but the data do not
- Checksum includes only the part that has changed
- If data were included, each router would need to recalculate the checksum for the whole packet which will increase processing time