Lecture 3: Network Layer & IP Addressing
Core Topics:
IP Addressing (IPv4/IPv6), Subnetting, Supernetting
Routing: Static vs Dynamic, Distance Vector vs Link State
Protocols: IP, ICMP, ARP, OSPF, RIPv2
What is IP Addressing ?
IP Address Structure:
• Definition: IP address is a unique number
which is used to identify network devices in
computer networks
• IP addresses contain two parts: a network
identifier and a host identifier
• The Network ID identifies the network on
which a device resides, while the Host ID
identifies the specific device within that
network
IP Addressing
1. Ethernet Header & Trailer (Data Link Layer)
• Purpose: To deliver data between two devices on the
same local network (LAN).
• Why it's used:
• Identifies source and destination MAC addresses
• Detects transmission errors (via trailer)
2. IP Header (Network Layer)
• Purpose: To route packets across networks and the
Internet.
• Why it's used:
• Adds source & destination IP addresses
• Ensures the packet reaches the correct remote
device
• Helps with fragmentation and reassembly
3. TCP Header (Transport Layer)
• Purpose: To ensure reliable communication
between devices.
• Why it's used:
• Enables connection-oriented transmission
• Ensures data is delivered in order and
4. Application Data (Application Layer)
without errors
• Purpose: The actual user content (e.g., webpage, file, message).
• Controls flow and handles retransmissions
• Why it's used:
if needed
• This is the useful data the user wants to send or receive
IP addresses are divided into 5 classes:
1. Subnetting: Dividing a large IP network into 2. Supernetting (also known as Prefix Aggregation or Route
smaller, logical networks (subnets). Summarization): Aggregating multiple IP networks into a
Purpose: larger, more concise network (supernet).
• Enhances network security by isolating traffic Purpose:
within each subnet. • Simplifies routing tables by reducing the number of routes
• Improves routing efficiency by reducing the needed to reach multiple networks.
• Improves router performance by reducing memory
number of broadcast domains.
requirements and processing overhead.
• Facilitates easier network management and
• Allows for more efficient IP address allocation and
control. management in large-scale networks.
How it works: How it works:
• Uses a subnet mask to define the network portion • Combines multiple network prefixes (the network portion
of an IP address and the host portion. of an IP address) into a single larger prefix.
• Each subnet has its own network address and a • Uses a less restrictive subnet mask to represent the
range of available host addresses. combined range of IP addresses.
Use Cases: Use Cases:
• Separating different departments or teams within • Reducing the size of routing tables in large ISPs or
an organization. enterprises.
• Creating secure, isolated zones for different • Simplifying routing configurations for large-scale networks.
services or applications. • Improving network performance by reducing routing
• Reducing network traffic by limiting broadcast overhead.
domains to smaller groups.
Subnetmask
• A subnet mask separates the network and host portions of an 128.143 137.144
IP address using a 32-bit binary number.
• It works by performing a bitwise AND operation between the IP network prefix host number
address and the subnet mask to identify the network address.
• Subnet masks are typically written in dotted decimal format, 128.143 137 144
such as 255.255.255.0, or in CIDR notation like /24.
• The number of 1s in the subnet mask determines the size of network prefix subnet host number
the network and how many hosts it can support. number
• Subnet masks are crucial for routing, as they help devices extended network prefix
determine whether a destination IP is local or must be sent
1111111111111111 1111111100000000
through a gateway.
subnetmask
Examples
Question 1: What is the network address if the destination address is 200.45.34.56 and the subnet
mask is 255.255.255.240?
Solution: We know the range of class C is from 192 to 223 so the given IP address belongs to class C. As
given subnet mask 255.255.255.240
To find the network address we perform ANDing operation between the IP address and subnet mask.
200.45.34.00111000 AND 255.255.255.11110000
we get 200.45.34.48 as a network address.
Question 2: A company is granted the site address 181.56.0.0. The company needs 1000 subnets.
Find the subnet mask
Solution: As we know the range of class B IP addresses in the first octet is from 128 to 191 so the given
address belongs to class B.
and the default subnet mask of class B is, 255.255.0.0
to get 1000 subnets we perform a log operation
log 1000=10
So, we require extra 10 bits from 255.255.00000000.00000000 to get the subnet mask i.e.;
255.255.00000000.000000000
So, the required subnet mask is 255.255.11111111.11000000 or 255.255.255.192
Special IP Addresses
• Reserved or (by convention) special addresses:
Loopback interfaces
• all addresses 127.0.0.1-127.255.255.255 are reserved for loopback interfaces
• Most systems use 127.0.0.1 as loopback address
• loopback interface is associated with name “localhost”
IP address of a network
• Host number is set to all zeros, e.g., 128.143.0.0
Broadcast address
• Host number is all ones, e.g., 128.143.255.255
• Broadcast goes to all hosts on the network
• Often ignored due to security concerns
• Test / Experimental addresses
Certain address ranges are reserved for “experimental use”. Packets should get dropped if they contain this destination address (see RFC
1918):
10.0.0.0 - 10.255.255.255
172.16.0.0 - 172.31.255.255
192.168.0.0 - 192.168.255.255
• Convention (but not a reserved address)
Default gateway has host number set to ‘1’, e.g., e.g., 192.0.1.1
Address assignment with subnetting
• Each part of the organization is allocated a range of IP addresses (subnets or
subnetworks)
• Addresses in each subnet can be administered locally
128.143.0.0/16
University
UniversityNetwork
Network
128.143.71.0/24 Engineering Medical 128.143.56.0/24
128.143.136.0/24 School School
Library
128.143.121.0/24
Classless Addressing in IP Addressing
• Classless Inter-Domain Routing (CIDR), or classless addressing, is an IP addressing method
that eliminates the rigid class structure of classful addressing.
Classless addressing does not use traditional IP
classes (A, B, C).
It uses a prefix length (e.g., /24) to determine
the network vs. host portion. IP
address/prefix length (e.g.,
192.168.1.0/24)
The prefix indicates how many bits are used for
the network
IPv6 - IP Version 6
• IP Version 6
• Is the successor to the currently used
IPv4
• Specification completed in 1994
• Makes improvements to IPv4 (no
revolutionary changes)
• One (not the only !) feature of IPv6
is a significant increase in of the IP
address to 128 bits (16 bytes)
• IPv6 will solve – for the foreseeable
future – the problems with IP
addressing
• 1024 addresses per square inch on the
surface of the Earth.
IPv6 Header
32 bits
version Traffic Class Flow Label
(4 bits) (8 bits) (24 bits)
Next Header
Payload Length (16 bits) Hop Limits (8 bits)
(8 bits)
Source IP address (128 bits)
Destination IP address (128 bits)
Ethernet Header IPv6 Header TCP Header Application data Ethernet Trailer
Ethernet frame
Routing: Static vs Dynamic, Distance Vector vs Link State
Static Routing:
what is routing in networking? • Routes are manually configured by network administrators.
Routing is the process of selecting the best path for data packets to • Simple to configure and use in small, stable networks.
travel across a network from a source to a destination • Less resource-intensive than dynamic routing.
The distance vector routing and link state routing are the two of routing • Offers predictable paths and faster network performance.
algorithms, categorised depending on the way the routing tables are • May require manual updates when network topology changes.
updated. Dynamic Routing:
Routing protocols dictate how data packets travel across a network. • Routes are dynamically adjusted based on real-time network
conditions.
• Suitable for larger, more complex networks that require
adaptability.
• Can handle network changes and failures more efficiently than
static routing.
• Uses complex routing algorithms and protocols (e.g., OSPF,
EIGRP, BGP).
• May be more resource-intensive than static routing.
Approaches to Shortest Path Routing
There are two basic routing algorithms found
on the Internet.
1. Distance Vector Routing
• Each node knows the distance (=cost) to its directly
connected neighbors
• A node sends periodically a list of routing updates to its
neighbors.
• If all nodes update their distances, the routing tables
eventually converge
• New nodes advertise themselves to their neighbors
2. Link State Routing
• Each node knows the distance to its neighbors
• The distance information (=link state) is broadcast to all
nodes in the network
• Each node calculates the routing tables independently 14
Interdomain and Intradomain Routing
Intradomain Routing Interdomain Routing
• Routing within an AS • Routing between AS’s
• Ignores the Internet outside the AS • Assumes that the Internet consists of a
• Protocols for Intradomain routing are also collection of interconnected AS’s
called Interior Gateway Protocols or IGP’s. • Normally, there is one dedicated router in
• Popular protocols are each AS that handles interdomain traffic.
• RIP (simple, old) • Protocols for interdomain routing are also
• OSPF (better) called Exterior Gateway Protocols or EGP’s.
• Routing protocols:
• EGP
• BGP (more recent)
15
Distance Vector vs. Link State Routing
• With distance vector routing, each node has information only about the
next hop:
• Node A: to reach F go to B
• Node B: to reach F go to D
• Node D: to reach F go to E AA BB CC
• Node E: go directly to F
• Distance vector routing makes
poor routing decisions if
directions are not completely
correct DD EE FF
(e.g., because a node is down).
• If parts of the directions incorrect, the routing may be incorrect until the routing algorithms has re-
converged.
16
Distance Vector vs. Link State Routing
• In link state routing, each node has a complete map of the topology
A B C A B C A B C
D E F D E F D E F
• If a node fails, each AA BB CC
node can calculate
the new route
DD EE FF
• Difficulty: All nodes need to
A B C
A B C A B C
have a consistent view of the D E F
D E F
D E F
network
17
18
Operation of a Link State Routing protocol
Link Dijkstra’s
Received Algorithm IP Routing
State
LSAs Table
Database
LSAs are flooded
to other interfaces
19
Dijkstra’s Shortest Path Algorithm for a Graph
Input: Graph (N,E) with
N the set of nodes and E the set of edges
dvw link cost (dvw = infinity if (v,w) E, dvv = 0)
s source node.
Output: Dn cost of the least-cost path from node s to node n
M = {s};
for each n M
Dn = dsn;
while (M all nodes) do
Find w M for which Dw = min{Dj ; j M};
Add w to M;
for each n M
Dn = minw [ Dn, Dw + dwn ];
Update route;
enddo 20
OSPF
• OSPF = Open Shortest Path First
• The OSPF routing protocol is the most
important link state routing protocol
on the Internet
• The complexity of OSPF is significant
• History:
• 1989: RFC 1131 OSPF Version 1
• 1991: RFC1247 OSPF Version 2
• 1994: RFC 1583 OSPF Version 2 (revised)
• 1997: RFC 2178 OSPF Version 2 (revised)
• 1998: RFC 2328 OSPF Version 2 (current
version)
21
Example Network
10.10.10.1 10.10.10.2 10.10.10.4 10.10.10.6
.1
4 .2 .2
2 .4 .4
1 .6
10.1.1.0 / 24 10.1.4.0 / 24 10.1.7.0 / 24
.1 .2 .4
.6
Router IDs are
3 2 3 1
10.1.3.0 / 24
10.1.6.0 / 24
selected
independent of
interface addresses
.3 .5
.3 5 .5
.3 .5
10.1.5.0/24
Link costs are called Metric 10.10.10.2 10.10.10.5
Metric is in the range [0 , 216]
Metric can be asymmetric
22
IP (Internet Protocol):
Purpose: IP is the primary protocol for addressing and routing data packets across networks. It assigns unique
IP addresses to devices, enabling them to be identified and located on the network.
Function: IP packets are encapsulated with IP headers containing source and destination IP addresses, along
with other information like time-to-live (TTL) and protocol type. Routers use IP addresses to determine the
optimal path for packet delivery.
Example: When a device wants to send data to another device with a different IP address, the IP protocol
encapsulates the data into a packet and sends it to the network layer, which then uses the IP addresses to
route the packet to the correct destination.
ICMP (Internet Control Message Protocol):
Purpose: ICMP is used for network diagnostics, error
reporting, and sending control messages. It helps identify
network problems and provide information about network
conditions.
Function: ICMP uses IP to send messages, which can
include requests (like ping) and error messages (like
destination unreachable).
Example: When a ping request fails, ICMP sends back an
error message (like "Destination Unreachable"), indicating
that the destination device is not responding or is
unreachable.
ARP (Address Resolution Protocol):
Purpose: ARP maps IP addresses to MAC addresses,
which are the physical addresses of network interface
cards (NICs). This mapping is necessary for devices on
the same network to communicate at the data-link layer.
Function: When a device wants to communicate with
another device on the same network, it uses ARP to find
the MAC address of the destination device based on its IP
address.
Example: If a device needs to send data to another
device on the same network with the IP address
192.168.1.100, it would use ARP to determine the MAC
address of that device, which it then uses to send the
RIPv1 Packet Format
IP header UDP header RIP Message 1: RIPv1
1: request
2: response
Command Version Set to 00...0
2: for IP
address family Set to 00.00
0…0: request full rou-
ting table 32-bit address
one route entry
(20 bytes)
Unused (Set to 00...0)
Address of destination
Unused (Set to 00...0)
Cost (measured in hops) metric (1-16)
Up to 24 more routes (each 20 bytes)
One RIP message can
have up to 25 route entries
26
32 bits
RIPv2 Packet Format
IP header UDP header RIP Message 2: RIPv2
1: request
2: response
Command Version Set to 00...0
2: for IP
address family Set to 00.00
0…0: request full rou-
ting table 32-bit address
one route entry
(20 bytes)
Unused (Set to 00...0)
Address of destination
Unused (Set to 00...0)
Cost (measured in hops) metric (1-16)
Up to 24 more routes (each 20 bytes)
One RIP message can
have up to 25 route entries
27
32 bits
Slow Learner Activities
Slow Learners Activity
Moderate Learner
Activities
Moderate Learners Activity
Fast Learner Activities
Fast Learners Activity