0% found this document useful (0 votes)
14 views45 pages

Computer Networks: IP Layer Essentials

The document provides an overview of the network layer functions, focusing on IP packet format, IPv4 addressing, and subnetting. It details how packets travel over TCP/IP networks, the structure and meaning of IP headers, and the classification of IPv4 addresses. Additionally, it discusses packet forwarding processes and methods for routers to manage routing tables effectively.

Uploaded by

Subah Ibnat
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views45 pages

Computer Networks: IP Layer Essentials

The document provides an overview of the network layer functions, focusing on IP packet format, IPv4 addressing, and subnetting. It details how packets travel over TCP/IP networks, the structure and meaning of IP headers, and the classification of IPv4 addresses. Additionally, it discusses packet forwarding processes and methods for routers to manage routing tables effectively.

Uploaded by

Subah Ibnat
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CN8810: Introduction to Computer Networks

Lecture 4

Baha Uddin Kazi, PhD


[Link]@[Link]
Lecture Outline

• Network Layer Functions


• IP Packet Format
• IPv4 Addressing
• IPv4 Subnetting
• Network Masking
Network Layer

5
Messages

4
Segment

3
Packet
2
Frame
1
Bits
Network Layer Function
• Specifies how packets travel end to end (host to host) over a TCP/IP network.
• Sending host takes a segment from transport layer, encapsulate each segment into a
datagram/packet and forwards to the lower layer (Data link layer).
• Receiving host takes packet from the lower layer (Data link layer), extract the segment
and forward that up to the transport layer.
• The key functions of the IP protocol:
• Addressing a machines over the Internet or any IP network
• Perform routing.

• IP does not guarantee reliable packet delivery over a network


IP Packet Format
IP protocol version 32 bits total datagram
number
length (bytes)
header length (4 bytes) Version Header Priority and Type
(4) length Of Service (8) Length (16)
Differentiated services for
Flags (3) Fragment offset (13)

20 bytes
or ”type” of data Identifier (16) fragmentation/
max number Upper layer reassembly
time to live (8) Header checksum (16)
remaining hops Protocol (8)
(decremented at
Source IP address (32)
each router)
Destination IP address (32)

upper layer protocol Options (if any) e.g. timestamp,


to deliver payload to record route
Data taken, specify
(variable length, typically a TCP or UDP segment) list of routers
to visit.

Maximum length is restrictrd by the maximum transmission unit (MTU) of the layer 2 technology. E.g: Ethernet: MTU=1500 byte
Header Fields and Meaning (Cont.)

• Version number (Ver)


• IPv4 or IPv6
• Header Length (Hlen)
• Integer multiple of 4 bytes
• Minimum length = 20 bytes; Maximum length = 60 bytes
• Type of Service (TOS)
• Provides different treatments to different traffic classes

6
Fragmentation
• Identification, d and m bits, fragment offset
• Used for fragmentation
• D= 0 or 1

IP header Data

IP header Fragment (N bytes) IP header Fragment

Fragment ID = 123 Fragment ID = 123


M=1 M=0
Frag. Offset = 0 Frag. Offset = N/8 (octets)

If M bit is 1 means more


packet is coming

7
Time-to-Live (TTL) Field
• The TTL value carried by a datagram indicates how many networks the datagram can traverse

Net 1 Net 2 Net 3

TTL=3 TTL=2 TTL=1

• Header checksum – one’s complement


• Options
• Source routing, routing record, etc …
• Protocol

9
Header Fields and Meaning
Field Meaning
Version Version of the IP protocol. Most networks use IPv4 today, with IPv6 becoming more popular. The header
format reflects IPv4.
Header Length Defines the length of the IP header, including optional fields. Because the length of the IP header must
always be a multiple of 4, the IP header length (IHL) is multiplied by 4 to give the actual number of bytes.
DS Field Differentiated Services Field. This byte was originally called the Type of Service (ToS) byte, but was
redefined by RFC 2474 as the DS Field. It is used for marking packets for the purpose of applying different
quality of service (QoS) levels to different packets.
Packet Length Identifies the entire length of the IP packet, including the data.
Identification Used by the IP packet fragmentation process. If a single packet is fragmented into multiple packets, all
fragments of the original packet contain the same identifier so that the original packet can be
reassembled.
Flags 3 bits used by the IP packet fragmentation process.
Fragment Offset A number set in a fragment of a larger packet that identifies the fragment’s location in the larger original
packet.
Time to Live (TTL) A value used to prevent routing loops. Routers decrement this field by 1 each time the packet is
forwarded; when it decrements to 0, the packet is discarded.
Protocol A field that identifies the contents of the data portion of the IP packet. For example, protocol 6 implies
that a TCP header is the first thing in the IP packet data field.
Header Fields and Meaning (Cont.)

Field Meaning
Header Checksum A value used to store a frame check sequence (FCS) value, whose purpose is to determine whether any
bit errors occurred in the IP header (not the data) during transmission.
Source IP Address The 32-bit IP address of the sender of the packet.
Destination IP The 32-bit IP address of the intended recipient of the packet.
Address
Optional Header IP supports additional header fields for future expansion through optional headers. Also, if these optional
Fields and Padding headers do not use a multiple of 4 bytes, padding bytes are added, composed of all binary 0s, so that the
header is a multiple of 4 bytes in length.
IP Addressing
IPv4 Address Structure
• An IP address is a numeric identifier assigned to each machine on an IP network.
• Two different versions: IPv4 and IPv6
• Address field is 32-bit long
• Dotted decimal number: [Link]
• These bits are divided into four sections or octets or bytes
• Consists of network ID and host ID

n bits 32-n bits


Net ID Host ID

• Hierarchical addressing
• All the hosts in the same network has the same network ID
• Network ID is used to locate the destination network and host ID is used to locate the destination
host in the destination network
13
IPv4 Addressing
• IPv4 address can handle 232 or about 4.3 billion addresses.
• [Link] to [Link]
• Addresses are assigned to network interfaces
• EX:
• Dotted-decimal, as in [Link]
• Binary, as in 10101100.00010000.00011110.00111000
• Hexadecimal, as in AC.10.1E.38
• Hierarchical addressing: network, subnet, and host
• A computer with an IP address assigned to an interface is an IP host
• Networks , subnets , or prefixes are actually groups of IP addresses.
• Groups are typically separated by routers.
• IP addresses can be analyzed using classful or classless logic.
• Classful address: Subdivide the entire address space into classes
IPv4 Address - Example

.1 .1
[Link] [Link]

[Link] e0 e0
[Link]
s1 s1

.2 [Link] [Link] .2
[Link] [Link]

Forwarding based on Last-hop delivery is


the Net ID based on the
complete address

15
IPv4 Addressing (Classful)

Classes Leading bits Num of Net 8 bits 8 bits 8 bits 8 bits Host per Net. Valid Net Add. Range
(0) Reserved
Class A (1-126) 0 126 Network Host Host Host 1/2 16777214 [Link] - [Link]
(127) Reserved
Class B (128-191) 10 16384 Network Network Host Host 1/4 65534 [Link] - [Link]
Class C (192-223) 110 2097152 Network Network Network Host 1/8 254 [Link] - [Link]
Class D (224-239) 1110 Multicast 1/16 [Link] – [Link]
Class E (240-255) 1111 Research 1/16

Class
Identifier
IPv4 Address Classes
• Class A address 1 3 (octets)
0nnnnnnn … hhhh …
Doted decimal format: Net ID Host ID

[0-126].h.h.h  h Є [0-255]
Class A site represents a large network which can support approximately 224 hosts
Example: [Link]
• Class B address 2 2 (octets)
10nnnn … … hhhh …
Net ID Host ID
• Doted Decimal format: [128-191].n.h.h  n and h Є [0-255]
• Maximum number of hosts ≈ 216
• Example: [Link]
• Class C address
3 1 (octets)
110nnnn … hhhhhhhh
Net ID Host ID
• Doted Decimal format: [192-223].n.n.h  n and h Є [0-255]
• Maximum number of hosts ≈ 28
• Example: [Link] 18
Private Addresses
• The addresses are not globally unique
• Designed to be used inside a private network
• Network address translation (NAT) is required for the communication between inside and outside
networks
• Save valuable IP address

• Three types of private addresses

Address Class Address Range


Class A [Link] – [Link]
Class B [Link] – [Link]
Class C [Link] – [Link]

19
Datagram Forwarding
Packet Forwarding

R1 R2

Step 1 (Same Network): If the destination IP address is in the same IP subnet as sender, send the packet
directly to the destination host. Use the Address Resolution Protocol (ARP) table entry or use ARP messages
to learn the destination host’s MAC Address.
Step 2 (Different Network): Find the default gateway’s MAC address and send the packet to the default
gateway, also known as a default router.

Who is the default gateway?


Default Gateway on a Host

Default Gateway
not needed
.10
PC1
[Link]/24
.1
.10 G0/0
PC2 Default Gateway
R1 needed
G0/1 .10
.1 PC1 [Link]/24
.1
.10 .11 G0/0
PC3 PC2

R1
.10 [Link]/24
PC4 G0/1
.1

.10
PC3

.11 [Link]/24
PC4
Packet Forwarding

R1 R2

Router Forwarding Logic:

1. Check the Frame Check Sequence (FCS) field to ensure that the frame has no errors; if errors, discard the frame.
2. If frame has no error, discard the old data-link header and trailer (de-encapsulate), leaving the IP packet.
3. Find the network address
• Compare the network address of the destination IP address to the routing table
• Find the best route that matches the destination address.
• This route identifies the outgoing interface of the router, and possibly the next-hop router IP address.
4. Encapsulate the IP packet inside a new data-link header and trailer, appropriate for the outgoing interface, and forward
the frame.
How a router learn or populate routing table?
How a Router Learn about the Networks and Route a Packet

• R1 Received Ethernet Frame • R2 Received HDLC Frame


• Extract IP Packet • Extract IP Packet
• Find the destination network in RT • Destination Network is a connected Network
• Encapsulate in HDLC • Encapsulate in Ethernet
HDLC IP Packet HDLC Eth-H IP Packet Eth-T

[Link]
Eth-H IP Packet Eth-T

F0/1 F0/1
R1 S0/0 R2
S0/0 [Link]

[Link]

Network Interface Network Interface


[Link]/24 F0/1 [Link]/24 F0/1
[Link]/24 S0/0 [Link]/24 S0/0
Methods a Router use to add Routes to Their Routing Table

▪ Connected routes:
▪ Router automatically adds a route to its routing table for the subnet connected to each interface.
▪ ip address interface subcommand.
• Static routes:
▪ Routes added to a routing table through direct configuration
▪ ip route global configuration Command
• Default route:
▪ If a packet does not match any other more specific route in the routing table, the router can at least
forward the packet to the default route.
▪ ip route global configuration Command
• Routing protocols:
▪ Routers dynamically tell each other about the network so that they all learn routes
Datagram Forwarding – Example 1

Routing table
Net ID Next Hop Intf
[Link] DC intf1
Router [Link] DC intf2
[Link] …
[Link]
[Link] DC intfn
[Link]
[Link] [Link] intf1
[Link] [Link] intf2

Interface Interface … Interface
Default [Link] intfn
1 2 n

Dest. IP Addr = [Link]

26
Datagram Forwarding – Example 2

.1
[Link] .1
e0 s1 s1 e0
[Link] [Link]
.10 1 .1 .2 2 .30
.2
.2

[Link] [Link]

Router 1 Routing Table Router 2 Routing Table


Net ID Intf Next Hop Net ID Intf Next Hop
[Link] e0 DC [Link] s1 [Link]
[Link] s1 DC [Link] s1 DC
[Link] s1 [Link] [Link] e0 DC

27
Subnetting
Subnetting

• Subnetting Concepts
• The original IP address class definitions do not reflect the practical network topologies
• Class A and class B networks have too many addresses
• Subnetting:
• Subdividing a single class A, B or C IP Network/Address into smaller groups
• Control traffic by containing broadcast traffic (such as DHCP) within each subnetwork.
• Reduce overall local network traffic and improve network performance.

29
Concept of IPv4 Subnetting
wastes a lot of
IP addresses
Subnetting
Communication Between Subnets
• A router is necessary for devices on different networks and subnets to communicate.
• Each router interface must have an IPv4 address that belongs to the network or subnet to which
the router interface is connected.
• Devices on a network and subnet use the router interface attached to their LAN as their default
gateway.

31
Subnetting IP Address
• Subnet Addressing
• The Host ID portion is further partitioned
• Part of it is used to identify the subnet
• What is the length of the subnet ID?
• The length of the subnet ID depends on the number of subnets or the number of addresses
required in each subnet

Original net ID Original Host ID

[Link] Subnet bits Host ID

New Network ID New Host ID


32
Design Concept of IP Subnet

Basic Steps:
1. Determine the number of required network IDs/subnets:
• One for each LAN subnet/VLAN (best practices: a one-to-one relationship between VLANs and IP subnets)
• One for each wide area network connection
2. Determine the number of required host IDs per subnet:
• One for each TCP/IP host
• One for each router interface
3. Based on the above requirements, create the following:
• A unique subnet mask for your entire network
• A unique subnet ID for each network segment
• A range of host IDs for each subnet
IP Subnetting - Subnet mask
• 32-bit value
• Defines the size of the subnet
• Distinguish the network ID portion and the host ID portion of the IP address
• 1 represent the network address and 0 represent host address

Default subnet mask for Class A, B and C?

Class Default subnet mask


A [Link]
B [Link]
C [Link]
Basic Subnetting - Example 1
• [Link]/24
• You need 2 subnetworks
• Borrowing 1 bit 21 = 2 subnets

Borrowing 1 Bit from the host portion creates 2 subnets with the same subnet mask

Subnet 0 Subnet 1
Network [Link]-127/25 Network [Link]-255/25
Mask: [Link] Mask: [Link]
Basic Subnetting - Example 1 (Cont.)
Subnet 0
Network [Link]-127/25

Subnet 1
Network [Link]-255/25
Basic Subnetting - Example 2
Choosing Enough Subnet and Host Bits
Ex:
• Class C Network id: [Link]
• 7 subnets
How many subnet bits do you need?
23≥7

[Link]/27

[Link]/27

[Link]/27

[Link]/27

[Link]/27
[Link]/27

[Link]/27
Subnetting - Example 3
Example:
• You have a network address [Link]
• You need four subnetworks with equal address space:

• 141.117.00000000.00000000
Address space: [Link] – [Link]
• 141.117.01000000.00000000
Address space: [Link] – [Link]
• 141.117.10000000.00000000
Address space: [Link] – [Link]
• 141.117.11000000.00000000
Address space: [Link] – [Link]

38
Subnetting – Network Mask
• Network mask
• Since the length of the Net ID is no longer pre-defined, network mask is required to
identify the new Net ID

[Link] netmask= [Link]

IP address: 10001101 . 01110101 . 00000101 . 00000001


net mask: 11111111 . 11111111 . 11111100 . 00000000

10001101 . 01110101 . 00000100 . 00000000

Net ID = [Link]

39
Network Mask
• Two ways to express network mask information:
• Dotted decimal – e.g. [Link] netmask:[Link]
• Length – e.g. [Link]/22

• Datagrams do not carry network mask information


• The routers and hosts get the netmask information from either Manual configuration or a routing
protocol
• The netmask information is stored in the routing table

40
Network Mask – Example
.4 H1
[Link]/18 e0 e1 [Link]/18
Subnet 1
R1 Subnet 2
.2

e0 .1 e1 Datagram:
R2 R3 [Link]→[Link]

e1 .1 e0

[Link]/18 .2 [Link]/18
Subnet 3 e1 R4 e0 Subnet 4

.130.7
H2

Routing Table of R3
R3 performs subnet masking to determine the subnet id. Net. ID. Intf. N.H.
[Link]/18 e1 [Link]
141.117.10000010.7 [Link]/18 e1 D.C.
255.255.11000000.0
[Link]/18 e0 [Link]
[Link]
[Link]/18 e0 D.C.
Subnetting - Hierarchical Routing
[Link]/16 Class B Site

[Link]/18 e0 R1 e1 [Link]/18
Subnet 1 Subnet 2
e0 e1
R2 R3 e0 R5
H2 e1 e0
[Link]/18 [Link]/18
R4 e0
Subnet 3 e1 Subnet 4

Routing Table of R3
Net. ID. Intf. N.H.
Routing Table of R5
[Link]/18 e1 [Link]
Net. ID. Intf. N.H.
[Link]/18 e1 D.C.
[Link]/16 e0 R3
[Link]/18 e0 [Link]

[Link]/18 e0 D.C.

In general, the router closer to the destination will have a longer mask.
Subnetting- Hierarchical Routing
• Example:

[Link]/30
e0 .1 .2 e0 [Link]/25
[Link]/24
e1 e2
e1
Route advertisement:
[Link]/24
[Link]/25
Routing table
Net ID Next Hop Intf Routing table
[Link]/24 DC e0
[Link]/30 DC e1 Net ID Next Hop Intf
[Link]/24 [Link] e1 [Link]/24 [Link] e2
[Link]/30 DC e2
[Link]/25 DC e0
[Link]/25 DC e1

45
How to Find the Subnet IDs using Decimal Number - Practice for You
1. Find the mask octets of value 255; copy the same decimal value from the IP address.
2. Find the mask octets of value 0; write down 0s for the same octets.
3. If any octet is not 255 or 0, that octet is the interesting octet.
1. Subtract the subnet mask’s value in the interesting octet from 256.
2. This difference is the “magic number.”
4. Find the integer multiple of the magic number that is closest to, but not larger than, the interesting octet’s
value.
Example:
What is the subnet
broadcast address?
Subnet address + Magic
number -1 and binary
value of host part is all 1

What are the all Subnets


of the Network ?
Static length subnet
masking (SLSM)
[Link], [Link], [Link] … [Link]
Subnetting Example - Practice for You
largest subnet mask available only be a /30 because you’ve got to keep at least 2 bits for host bits.

Network address: [Link]


Subnet mask: [Link]
1. Class : C; Network bits:24
2. How many subnets ? 192 is 2 bits on in the last octet (11000000), the answer would be 22 = 4 subnets
3. How many host per subnet? Remaining 6 host bits(11000000), giving us 26 – 2 = 62 hosts
4. What are the valid subnets? 256 – 192 = 64. Remember, to start at zero and add your magic number. This
means our subnets are 0, 64, 128, and 192.
Practice Problem
Thank you

"Having gratitude unlocks the fullness of life” – Melody Beattie

You might also like