How The TCP/IP Protocol Works: Les Cottrell - SLAC
How The TCP/IP Protocol Works: Les Cottrell - SLAC
Overview
This is not a lecture on how to program TCP/IP,
rather an introduction to how major portions works
IP
Addressing: IP addresses, ARP, routing
ICMP
UDP
TCP: flow control, error recovery, establishment,
diconnect
References:
Internetworking with TCP/IP, volume I, principles, protocols & Architecture,
by Douglas Comer
TCP/IP Illustrated: the protocols, by W. Richard Stevens
Most information also available free via Web searches
2
Internet datagram
Basic transfer unit
Datagram header
IP Fragmentation
How do we send a datagram of say 1400 bytes through a
link that has a Maximum Transfer Unit (MTU) of say 620
bytes?
Answer the datagram is broken into fragments
Net 1
MTU=1500
Net 2
MTU=620
Net 3
MTU=1500
Fragmentation Control
Identification: copied into fragment, allows destination to
know which fragments belong to which datagram
Fragment Offset (12 bits): specifies the offset in the original
datagram of the data being carried in the fragment
Measured in units of 8 bytes starting at 0
More Fragments (least sig bit): tells receiver it has got last fragment
Offset=0
More frags
Offset=1480
More frags
Offset=2960
More frags
Offset=3440
Last frag
Internet Addressing
IP address is a 32 bit integer
Refers to interface rather than host
Consists of network and host portions
Enables routers to keep 1 entry/network instead of 1/host
Subnets
A subnet mask is applied to the host bits to
determine how the network is subnetted, e.g. if the
host is: 137.138.28.228, and the subnet mask is
255.255.255.0 then the right hand 8 bits are for the
host (255 is decimal for all bits set in an octet)
Host addresses of all bits set or no bits set, indicate a
broadcast, i.e. the packet is sent to all hosts.
12
Prefix
Length
Subnet Mask
/1
/2
/3
/4
/5
/6
/7
/8
/9
/10
/11
/12
/13
/14
/15
/16
128.0.0.0
192.0.0.0
224.0.0.0
240.0.0.0
248.0.0.0
252.0.0.0
254.0.0.0
255.0.0.0
255.128.0.0
255.192.0.0
255.224.0.0
255.240.0.0
255.248.0.0
255.252.0.0
255.254.0.0
255.255.0.0
Prefix
Length
/17
/18
/19
/20
/21
/22
/23
/24
/25
/26
/27
/28
/29
/30
/31
/32
Subnet Mask
255.255.128.0
255.255.192.0
255.255.224.0
255.255.240.0
255.255.248.0
255.255.252.0
255.255.254.0
255.255.255.0
255.255.255.128
255.255.255.192
255.255.255.224
255.255.255.240
255.255.255.248
255.255.255.252
255.255.255.254
255.255.255.255
Decimal Octet
Binary Number
128
192
224
240
248
252
254
255
1000 0000
1100 0000
1110 0000
1111 0000
1111 1000
1111 1100
1111 1110
1111 1111
13
Address depletion
In 1991 IAB identified 3 dangers
Running out of class B addresses
Increase in nets has resulted in routing table explosion
Increase in net/hosts exhausting 32 bit address space
Private IP Addresses
IP addresses that are not globally unique, but used
exclusively in an organization
Three ranges:
10.0.0.0 - 10.255.255.255 a single class A net
172.16.0.0 - 172.31.255.255 16 contiguous class Bs
192.168.0.0 192.168.255.255 256 contiguous class Cs
17
ARP cont.
ARP requests are local only, do not cross routers
Subnet 1
134.79.10.17
134.79.10.1
Subnet 2
134.79.15.1
User A
134.79.15.3
User B
Routing
Routers must select next hop for packet
Get route information from other routers via a
routing protocol (RIP, OSPF, EIGRP etc.)
Note the following are non-routable:
private networks: 10.0.0.0/8, 172.16.0.0/12,
192.168.0.0/16
Loopback 127.0.0.0/24
21
Packet format
0
8
16
24
31
Type
Code
Checksum
ICMP data (depends on type/code)
22
ICMP
Echo reply, ping
Destination unreachable (code 1 host, code 3 port)
DF and must fragment (code 4)
4
5
8
11
12
Source quench
Redirect (change a route)
Echo request
Time exceeded (code 0 ttl=0, code 1 reassembly)
Parameter problems
23
ICMP Echo/Ping
Very commonly used diagnostic tool
Implementations vary between OS
Build echo request
0
8
16
24
31
Type=8 Code=0
Checksum
Identifier
Sequence number
Optional data
Identifier used to match request to replies (e.g. pid)
Sequence number, starts at 0 increments by 1 for each ping packet
Used to detect loss, reorder, duplicates
Unreachable
76cottrell@flora06:~>ping islamabad-server2.comsats.net.pk
ICMP 13 Unreachable from gateway 207.45.205.18
for icmp from FLORA06.SLAC.Stanford.EDU (134.79.16.101)
to islamabad-server2.comsats.net.pk (210.56.8.8)
26
Time Exceeded
0
8
Type 11 Code
16
24
31
Checksum
Unused
Internet header & 8 bytes of data
MTU Discovery
Transport
Network
Port 1
Port 2
Port 1
Port 2
Demux on
Port number
UDP
TCP
IP
Demux on
IP protocol
16
24
31
Source port
Destination port
UDP message len Checksum (opt.)
Data
UDP applications
Message oriented, e.g. SNMP, DNS, time
File system, e.g. NFS, AFS
Lightweight file transfer, e.g. tftp, bootp
31
TCP layering
App.
Port 1
Transport
Port 2
Port 1
UDP
TCP
IP port 6
Network
Port 2
IP
Demux on
Port number
Demux on
IP protocol
To ID connection need:
Source: (address, port) AND Destination: (address, port)
Only need one port on host to allow multiple connections, since each
connection will have different (host, port) at other end
E.g. single host can serve multiple telnet connections
Rcv ACK 2
Rcv pkt 1
Send ACK 1
Time
Rcv ACK 1
Send pkt 2
Receiver site
Rcv pkt 2
Send ACK 2
Network messages
34
Receiver site
Loss
Rcv pkt 1
Send ACK 1
Network messages
35
Window slides
2 3 4 5 6 7 8
2 3 4 5 6 7 8
Packets to be sent
Src
Rcv
RTT
K
C
A
37
Implementation
Sliding window operates at byte level, NOT packet
Current window
1
2 3 4 5 6 7 8
3 pointers
39
10
16
24
31
Source port
Destination port
Sequence number
Acknowledgement number
Hlen Resv Code
Window
Checksum
Urgent ptr
Options (if any)
Padding
Data if any
41
TCP timeout
RTT ms.
Time of day
Timeout=beta * RTTs
Timeout= RTTs + eta{=4}*f(dev(RTTs))
Active
Send SYN seq x Win
4096, mss
1024
i ve
s
s
a
P
Rcv SYN/ACK
4
2
0
1
s
s
m
,
6
9
Win 40
Send ACK y+1
Site 2
Rcv SYN segment
Send SYN seq=y, ACK x+1
Rcv ACK segment
Site 1
(App closes)
Send FIN seq=x
Rcv ACK segment
Site 2
Rcv FIN segment
Send ACK x=1
(inform app)
45
More Information
Lectures, tutorials etc:
www.nv.cc.va.us/home/joney/tcp_ip.htm
www.cs.pdx.edu/~jrb/tcpip.lectures.html
www.raleigh.ibm.com/cgi-bin/bookmgr/BOOKS/EZ306200/CCONTENTS
www.cisco.com/univercd/cc/td/doc/product/iaabu/centri4/user/scf4ap1.htm
www.cis.ohio-state.edu/htbin/rfc/rfc1180.html
www.jbmelectronics.com/tcp.htm
Encylopaedia
http://www.freesoft.org/CIE/index.htm
TCP/IP Resources
www.private.org.il/tcpip_rl.html
Understanding IP addresses
http://www.3com.com/solutions/en_US/ncs/501302.html
47
Session start
SLAC>CERN: 256kbyte window,1 stream,
full speed > 30msec, 13MBytes in 20s, 5.1MBytes/s
Congestion window