Lecture 6 - Internet Layer
Lecture 6 - Internet Layer
Internet Layer
1
Contents
Internet Protocol
IP address and IP packet format
ICMP- Protocol for control message
2
Introduction about IP
Concepts
Store and forward principles
Characteristic of IP
3
Network layer and Internet
protocol
Role of network layer: Transferring data between distant nodes
Two main functionalities of Network layer
Routing: Determine the path for transferring data from the source
to the destination nodes Role of routing protocol.
Forwarding: Transferring data from the an incoming port to an
outgoing port of a node (router) according to the path defined
above Role of routed protocol: Internet Protocol (IP)
application
application
TCP/UDP
TCP/UDP
IP
IP
data link 1. Send data 2. Receive data data link
physical
physical
4
Network layer and Internet
protocol
Layer 2 devices allow to connect limited
number of close hosts
When hosts are far from each other,
intermediates nodes with forwarding and path
finding functionality is needed Router
Finding routes
Forwarding data according to destination Network
layer address
5
IP principles
Elements
host = end system;
subnetwork = a collection of hosts that are connected by layer-2
devices
Host of the same subnetwork have similar addresses: a common
prefix
Routers: intermediate nodes interconnect subnetworks:
Packet forwarding
direct: inside a subnetwork hosts communicate directly without
routers, layer-2 device (switch) delivers packets to hosts
indirect: between subnetworks one or several routers forward
packets based on
structured address space
routing tables: aggregation of entries
6
IP Routing and forwarding
Source IP address
payload IP header Destination IP address
Host
Router
• Routing according to
destination address
Router
• Host with similar address 7
should be in the same region Host
IP forwarding
Routing table
Each router have a routing table telling where to forward a packet
9
IP address
IP address classes
CIDR – Classless Inter-Domain routing
Subnet and netmask
Special IP addresses
10
IP address (IPv4)
IP address: A 32-bit
223.1.1.1
number identifying
uniquely a network 223.1.1.2
223.1.2.1
223 1 1 1
11
IP address (IPv4)
For routing purpose, IP a 223.1.1.1
address of interfaces in
223.1.2.1
the same subnetwork 223.1.1.2
223.1.1.4 223.1.2.9
have the same prefix.
What’s a subnetwork? 223.1.1.3 223.1.3.27
223.1.2.2
(from IP address perspective)
device interfaces with same
prefix
223.1.3.1 223.1.3.2
can physically reach each
other without intervening
router (using layer 2
A subnetwork
technology only)
12
Dot notation
Example:
203.178.136.63 o
259.12.49.192 x
133.27.4.27 o
8 bits
0 – 255 integer
3417476964
1 1 0 0 1 0 1 1 1 0 1 1 0 0 1 0 1 0 0 0 1 1 1 1 0 1 1 0 0 1 0 0
1 1 0 0 1 0 1 1 1 0 1 1 0 0 1 0 1 0 0 0 1 1 1 1 0 1 1 0 0 1 0 0
Class A 0 7bit H H H
Class B 1 0 6bit N H H
Class C 1 1 0 5bit N N H
Class D 1 1 1 0 Multicast
Class E 1 1 1 1 Reserve for future use
# of network # of hosts
Class A 128 2^24
Class B 16384 65536
15
Class C 2^21 256
Exercise
Determine which classes do these IP
addresses belong to:
10.10.10.9
192.168.70.5
129.60.4.7
16
Limitation of classful IP address
Inefficient use of addressing space
Hard classification of addressing space into classes (A, B,
C, D, E) makes it is difficult to use all the address space
Solution…
CIDR: Classless Inter Domain Routing
Network ID part will have variable length.
Length of Network ID part is specified in Network mask
Address notation: a.b.c.d/x, where x (mask) the number of
bit of Network ID part.
17
Network mask
Network mask divides the IP address into two
parts
Part corresponding to Host ID
Part corresponding to Network ID
IP addresses are assigned to hosts so that all
hosts in the same network have the same
Network ID part.
Based on Network mask, it is possible to
Identify the network where an IP address belongs to
Calculate how many IP addresses available in the network
associated with the mask. 18
Presentation of network mask
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0
AND
27 (bit)
203 . 178 . 142 . 128
11001011 10110010 10001110 10000000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0
64 - 127
128 - 191
192 – 255
Including network
address and broadcast 21
address
Network address or host
address (1)
133 27 4 160
10000101000110110000010010100000
1 1111111111111111111111111000000
1 0000101000110110000010010000000
133 27 4 128
22
Network address or host
address (2)
133 27 4 160
10000101000110110000010010100000
1 1111111111111111111111111100000
1 0000101000110110000010010100000
133 27 4 160
23
Different significations of IP
address
Network address
IP address assigned to a network
hostID contains all 0
Host address
IP address assigned to a network card
Broadcast address
Address used for sending data to all hosts in a
network
All bit 1 in HostID part.
24
Exercice: IP address and
network mask
Which of the following IP addresses are host
address, network address, broadcast address?
(1) 203.178.142.128 /25
25
Subnet
Subnet is a part of a
223.1.1.1
network
223.1.2.1
Hosts of a subnet 223.1.1.2
communicate directly 223.1.1.4 223.1.2.9
without reaching to
223.1.2.2
layer 3. 223.1.1.3 223.1.3.27
Usually is one
subnet
department of an
organization 223.1.3.1 223.1.3.2
27
Principle
Divide a IP range into sub-ranges of equal size
Take some bits from HostID part to distinguish
subnets
each subnet contains IP addresses with a fixed values
of subnet ID.
Network ID Host ID
subnetID
28
network ID of each subnet
Exercise: Dividing into
subnets
Given IP addresses in the range 200.23.16.0/24
1) Need to organize into 8 subnets
Address of each subnetwork? Mask? Number of
hosts/network
200.23.16.0 /27
2) General question: Need to create N subnets.
Network address? Mask?
Each network contains 14 hosts /28
Each network contains 30 hosts /27
Each network contains 31 hosts /26
29
10.0.0.0/8
Private address 172.16.0.0/12
192.168.0.0/16
Loopback address 127.0.0.0
224.0.0.0
Multicast address
~239.255.255.255
32
IP package
33
Header of IP
total datagram
length (words)
IP protocol version
number 32 bits
head.
header length ver DS length
len for
(bytes) fragment
16-bit identifier flgs fragmentation/
offset reassembly
QoS support time to upper header
live layer checksum
max number 32 bit source IP address
remaining hops
(decremented at 32 bit destination IP address
each router) E.g. timestamp,
Options (if any)
record route
data taken, specify
upper layer protocol (variable length, list of routers
to deliver payload to typically a TCP to visit.
or UDP segment)
34
IP header (1)
Version (4 bits)
IPv4
IPv6
Header length: 4bits
In word unit (4 bytes)
Min: 5
Max: 60
35
IP header (2)
DS (Differentiated Service : 8bits)
Old name: Type of Service
Used for QoS management by some router
Diffserv
36
IP header (3)
Length: total length including header (16 bits)
In bytes unit
Max: 65536
16 bits Identifier– ID of the packet
Used for identifying all fragments of the same packet when
it is fragmented
Flag
Fragmentation offset – offset of the first byte of
the fragment in its original packet
37
IP header (4)
TTL, 8 bits – Time to live
Maximum number of hops (router) the packet is allowed to
travel
Max: 255
Router decreases TTL 1 unit when processing a packet
The packet will be destroyed when TTL reaches to 0
Protocol – upper layer protocol
Transport protocol (TCP, UDP,…)
Other network layer protocols that are encapsulated in IP
packet (ICMP, IGMP, OSPF )
38
IP header (4)
Checksum: to detect corruption in the header
of IPv4 data packets
Source IP address
32 bit, address of the sender
Destination IP address
32 bit, address of the receiver.
39
Packet fragmentation (1)
Each link has a fixed
MTU (Maximum Phân mảnh:
transfering unit) in: 1 gói tin lớn
out: 3 gói tin nhỏ hơn
Different media have
different MTU
If IP packet > MTU, it Hợp nhất
should be
Divided into small fragments
Gathered at the destination
40
Packet fragmentation (2)
Offset
Position of the fragment in the original packet
In 8 bytes units
0 1399
Offset = 0/8 = 0
2800 3999
Offset = 2800/8 = 350
41
Internet Control Message Protocol
Packet format
Ping and Traceroute
42
Idea of ICMP (1)
IP is unreliable, connectionless
Lack of supporting and error control mechanism
ICMP is used in network layer for providing
information exchange between sender and
receivers
Error information: inform that a packet cannot reach
a host, a network or a port.
43
Idea of ICMP (2)
ICMP message
44
IP header and Protocol field
45
ICMP message format
Type: type of ICMP message
Code: cause of error
Checksum
Rest of header varies according on type
0 78 15 16 31
Type Code Checksum
Data
46
Some ICMP message types
3 Destination Unreachable
4 Source quench (nguồn giảm tốc độ)
Error-reporting
ICMP Message Type
5 Redirection
messages
11 Time exceeded
12 Parameter problem
8 or 0 Echo reply or request
47
ICMP and debuging tools
ICMP always works transparently for users
Users can use ICMP by using some
debuging tools
ping
traceroute
48
Ping and ICMP
ping
Test a connection
Sender sends packet “ICMP echo request”
Receiver responses with “ICMP echo reply”
Data field contains the time stamp when the
packet is sent
For calculating RTT (round-trip time)
49
Ping: Example
50
Traceroute and ICMP
Sender send many packets to receiver
First packet has TTL =1
51
Traceroute and ICMP
Termination condition
When ICMP echo packet arrive to the destination
3 probes 3 probes
3 probes
52
Traceroute: Example
C:\Documents and Settings\hongson>tracert www.jaist.ac.jp
Trace complete.
53
Network address
translation
54
NAT: network address translation
NAT: all devices in local network share just one IPv4 address as
far as outside world is concerned
rest of local network (e.g., home
Internet network) 10.0.0/24
10.0.0.1
138.76.29.7 10.0.0.4
10.0.0.2
10.0.0.3
all datagrams leaving local network have datagrams with source or destination in
same source NAT IP address: 138.76.29.7, this network have 10.0.0/24 address for
but different source port numbers source, destination (as usual)
NAT: network address translation
all devices in local network have 32-bit addresses in a “private” IP
address space (10/8, 172.16/12, 192.168/16 prefixes) that can only
be used in local network
advantages:
just one IP address needed from provider ISP for all devices
can change addresses of host in local network without notifying
outside world
can change ISP without changing addresses of devices in local
network
security: devices inside local net not directly addressable, visible
by outside world
NAT: network address translation
implementation: NAT router must (transparently):
outgoing datagrams: replace (source IP address, port #) of every
outgoing datagram to (NAT IP address, new port #)
• remote clients/servers will respond using (NAT IP address, new port
#) as destination address
remember (in NAT translation table) every (source IP address, port #)
to (NAT IP address, new port #) translation pair
incoming datagrams: replace (NAT IP address, new port #) in
destination fields of every incoming datagram with corresponding
(source IP address, port #) stored in NAT table
NAT: network address translation
NAT translation table
2: NAT router changes 1: host 10.0.0.1 sends
WAN side addr LAN side addr datagram to
datagram source address
from 10.0.0.1, 3345 to 138.76.29.7, 5001 10.0.0.1, 3345 128.119.40.186, 80
138.76.29.7, 5001, …… ……
updates table
S: 10.0.0.1, 3345
D: 128.119.40.186, 80
10.0.0.1
1
S: 138.76.29.7, 5001
2 D: 128.119.40.186, 80 10.0.0.4 10.0.0.2
138.76.29.7 S: 128.119.40.186, 80
D: 10.0.0.1, 3345
4
S: 128.119.40.186, 80 10.0.0.3
D: 138.76.29.7, 5001 3
3: reply arrives, destination
address: 138.76.29.7, 5001
59
ARP: address resolution protocol
Question: how to determine interface’s MAC address, knowing its IP
address?
ARP table: each IP node (host,
ARP
router) on LAN has table
137.196.7.78
ARP
1A-2F-BB-76-09-AD • IP/MAC address mappings for
ARP some LAN nodes:
LAN < IP address; MAC address; TTL>
71-65-F7-2B-08-53
137.196.7.23
58-23-D7-FA-20-B0
137.196.7.14 • TTL (Time To Live): time after
ARP 0C-C4-11-6F-E3-98 which address mapping will be
137.196.7.88
forgotten (typically 20 min)
ARP protocol in action
example: A wants to send datagram to B
• B’s MAC address not in A’s ARP table, so A uses ARP to find B’s MAC address
D
ARP protocol in action
example: A wants to send datagram to B
• B’s MAC address not in A’s ARP table, so A uses ARP to find B’s MAC address
C
ARP table in A
IP addr MAC addr TTL TTL
137.196.7.14 58-23-D7-FA-20-B0 500 A B
71-65-F7-2B-08-53 58-23-D7-FA-20-B0
137.196.7.23 137.196.7.14
A B
R
111.111.111.111
74-29-9C-E8-FF-55 222.222.222.222
49-BD-D2-C7-56-2A
222.222.222.220
1A-23-F9-CD-06-9B
111.111.111.112 111.111.111.110
CC-49-DE-D0-AB-7D E6-E9-00-17-BB-4B 222.222.222.221
88-B2-2F-54-1A-0F
Routing to another subnet: addressing
A creates IP datagram with IP source A, destination B
A creates link-layer frame containing A-to-B IP datagram
• R's MAC address is frame’s destination
MAC src: 74-29-9C-E8-FF-55
MAC dest: E6-E9-00-17-BB-4B
IP src: 111.111.111.111
IP dest: 222.222.222.222
IP
Eth
Phy
A B
R
111.111.111.111
74-29-9C-E8-FF-55 222.222.222.222
49-BD-D2-C7-56-2A
222.222.222.220
1A-23-F9-CD-06-9B
111.111.111.112 111.111.111.110
CC-49-DE-D0-AB-7D E6-E9-00-17-BB-4B 222.222.222.221
88-B2-2F-54-1A-0F
Routing to another subnet: addressing
frame sent from A to R
frame received at R, datagram removed, passed up to IP
IP IP
Eth Eth
Phy Phy
A B
R
111.111.111.111
74-29-9C-E8-FF-55 222.222.222.222
49-BD-D2-C7-56-2A
222.222.222.220
1A-23-F9-CD-06-9B
111.111.111.112 111.111.111.110
CC-49-DE-D0-AB-7D E6-E9-00-17-BB-4B 222.222.222.221
88-B2-2F-54-1A-0F
IP
Et
h
Ph
A y
B
R
111.111.111.111
74-29-9C-E8-FF-55 222.222.222.222
49-BD-D2-C7-56-2A
222.222.222.220
1A-23-F9-CD-06-9B
111.111.111.112 111.111.111.110
CC-49-DE-D0-AB-7D E6-E9-00-17-BB-4B 222.222.222.221
88-B2-2F-54-1A-0F
A B
R
111.111.111.111
74-29-9C-E8-FF-55 222.222.222.222
49-BD-D2-C7-56-2A
222.222.222.220
1A-23-F9-CD-06-9B
111.111.111.112 111.111.111.110
CC-49-DE-D0-AB-7D E6-E9-00-17-BB-4B 222.222.222.221
88-B2-2F-54-1A-0F
IP src: 111.111.111.111
IP dest: 222.222.222.222
IP
IP Eth
Eth Phy
Phy
A B
R
111.111.111.111
74-29-9C-E8-FF-55 222.222.222.222
49-BD-D2-C7-56-2A
222.222.222.220
1A-23-F9-CD-06-9B
111.111.111.112 111.111.111.110
CC-49-DE-D0-AB-7D E6-E9-00-17-BB-4B 222.222.222.221
88-B2-2F-54-1A-0F
70
DHCP: Dynamic Host
Configuration Protocol
goal: host dynamically obtains IP address from network server when it
“joins” network
can renew its lease on address in use
allows reuse of addresses (only hold address while connected/on)
support for mobile users who join/leave network
DHCP overview:
host broadcasts DHCP discover msg [optional]
DHCP server responds with DHCP offer msg [optional]
host requests IP address: DHCP request msg
DHCP server sends address: DHCP ack msg
DHCP client-server scenario
Typically, DHCP server will be co-
DHCP located in router, serving all
223.1.1.1 server subnets to which router is attached
223.1.2.1
223.1.2.5
223.1.1.2
223.1.1.4 223.1.2.9
223.1.1.3
223.1.3.27 arriving DHCP client needs
223.1.2.2 address in this network
223.1.3.1 223.1.3.2
DHCP client-server scenario
DHCP server: 223.1.2.5 DHCP discover Arriving client
src : 0.0.0.0, 68
Broadcast: is there a
dest.: 255.255.255.255,67
DHCPyiaddr:
server 0.0.0.0
out there?
transaction ID: 654
DHCP offer
src: 223.1.2.5, 67
Broadcast: I’m a DHCP
dest: 255.255.255.255, 68
server!
yiaddrr:Here’s an IP
223.1.2.4
transaction
address youID:can
654 use
lifetime: 3600 secs
The two steps above can
DHCP request be skipped “if a client
src: 0.0.0.0, 68 remembers and wishes to
dest:: 255.255.255.255, 67
Broadcast: OK. I would reuse a previously
yiaddrr: 223.1.2.4
like totransaction
use this ID:IP655
address! allocated network
lifetime: 3600 secs address” [RFC 2131]
DHCP ACK
src: 223.1.2.5, 67
dest: 255.255.255.255,
Broadcast: 68
OK. You’ve
yiaddrr: 223.1.2.4
got that IPID:
transaction address!
655
lifetime: 3600 secs
DHCP: more than IP addresses
DHCP can return more than just allocated IP address on
subnet:
address of first-hop router for client
name and IP address of DNS sever
network mask (indicating network versus host portion of address)
Extend using
DHCP Client DHCP Server
Limit time extend
t = 0.5*T, client sends
DHCP Request to DHCP t = 0.5*T
Server to request
extension
No DHCP ACK, then t =
Other Server
0.875*T, client sends the
t = 0.875*T
broadcast DHCP Request
No DHCP ACK, while t =
T, client sends DHCP
Discover
t=T 75
DHCP Relay
DHCP Server stays on another subnet broadcast
packets will be forwared by routers
DHCP Relay on routers