Académique Documents
Professionnel Documents
Culture Documents
Notes
Lecture 18
UDP and TCP
Martin C. Rinard
IP delivers packets to machines. But, need higher level abstractions. UDP delivers
packets to ports on machines; TCP provides reliable, stream-based communication to a
port on a machine.
hat is a port! It is an abstraction "or a communication point. # process can read and
$rite data to and "rom a port. %ne machine can have multiple ports. Usuall&, dedicate
ports to di""erent "unctions. 'ave an "tp port, a de"ault telnet port, a mail port, etc.
UDP message contains a header and data. UDP header contains(
o )ource Port( port "rom $hich message $as sent.
o Dest Port( destination port on destination machine.
o *ength( length o" UDP packet.
o UDP checksum( checksum.
To send a UDP packet, encapsulate it in an IP packet, then send the IP packet to the
appropriate machine. The $hole UDP packet is in the data area o" the IP packet.
The %) on the machine $ill receive the IP packet, reali+e that it contains a UDP packet,
then pass the UDP packet on to the process $aiting "or input on the destination UDP port.
The %) reali+es that the IP packet contains a UDP packet b& looking at the protocol "ield
in the IP header.
hen sending a UDP packet to a machine, $hat port should it be sent to! There are a set
o" $ell-kno$n ports that provide standard services available via UDP. ell-kno$n ports
go "rom , to -.., and onl& root processes can read or $rite "rom ports $ith these
numbers. #n e/ample( port 01 is the "inger port. Port 21 is the Trivial 3ile Trans"er
Protocol 4T3TP5 port. B& convention, all machines use these port numbers "or these
services.
T$o applications running on di""erent machines can also agree to use their o$n port
numbers "or their o$n communication. T&picall&, %) d&namicall& allocates port numbers
on re6uest and the applications use those 4a"ter setting up the port number
communication via some other mechanism5.
UDP does not provide reliable deliver&. Users must implement their o$n reliabilit&.
There is a need "or a reliable protocol. )o, have TCP.
TCP provides abstraction o" a reliable, t$o $a& data stream. It is la&ered on top o" IP 7ust
like UDP, but is a heavier $eight protocol.
Concept o" a stream abstraction. # stream is 7ust a se6uence o" characters. There are no
packet boundaries like there are $ith UDP and IP. The so"t$are breaks the stream up into
packets, $ith the subdivision invisible to the application program. T&picall&, TCP
connections bu""er up more than one character be"ore issuing an IP packet. But, can "orce
data deliver& i" $ant to.
To get reliabilit& use a positive ackno$ledgement $ith timeout scheme. hen send
something over a TCP connection, e/pect to get an #C8 back in a "i/ed amount o" time.
I" don9t get the #C8, assume data $as lost and retransmit.
TCP optimi+es communication b& using a sliding $indo$. Instead o" sending one IP
packet and $aiting "or the #C8, it can have multiple outstanding un#C8ed packets.
Basic idea is to "ill the net$ork pipe bet$een sender and receiver $ith data. 8eep a
stead& state $ith sender al$a&s sending and receiver al$a&s #C8ing.
TCP also has port abstraction - a TCP connection goes bet$een t$o ports. To set up a
TCP connection, use a three-$a& handshake. Initiator sends a re6uest, receiver sends an
#C8, then sender sends back an #C8 to establish connection.
Can close a TCP connection.
Building services on top o" TCP and UDP. T&picall&, use a client-server architecture.
Basic idea(
o )erver $aits at a $ell-kno$n port "or client re6uests to come in. T&pical TCP
server ports( -: is Telnet, -. is );TP 4)imple ;ail Transport Protocol5, -< is
3TP.
o Client allocates a local port number and sends it to server at $ell-kno$n port.
)erver $ill communicate $ith client using the allocated local port number.
o hen server gets re6uest, it allocates its o$n local port number and spa$ns a
process to provide service. The process connects up $ith client over the local
ports.
o Client and spa$ned server process communicate over the established connection.
#lmost all Internet services done this $a&. 3TP, telnet, etc. all $ork this $a&. ;an&
services are 7ust character-oriented streams, and can interact $ith them at the terminal.
In general, la&er services on top o" communications protocols. Can build arbitrar& la&ers.
The packets "or each service 7ust get encapsulated in the packets o" lo$er-level services.
=/ample "rom snooped net$ork here at UC)B. )omeone is using >3) to look up a "ile
4in this case a$k5.
ETHER: ----- Ether Header -----
ETHER:
ETHER: Packet 17 arrived at 9:44:30.37
ETHER: Packet size = 194 bytes
ETHER: esti!atio! = ":0:#0:1#:$e:"d% &'!
ETHER: &o'rce = ":0:#0:1#:77:#a% &'!
ETHER: Etherty(e = 0"00 )*P+
ETHER:
*P: ----- *P Header -----
*P:
*P: ,ersio! = 4
*P: Header -e!.th = #0 bytes
*P: Ty(e o/ service = 0000
*P: 000. .... = 0 )(recede!ce+
*P: ...0 .... = !or1a- de-ay
*P: .... 0... = !or1a- thro'.h('t
*P: .... .0.. = !or1a- re-iabi-ity
*P: Tota- -e!.th = 1"0 bytes
*P: *de!ti/icatio! = 1$"##
*P: 2-a.s = 004
*P: .1.. .... = do !ot /ra.1e!t
*P: ..0. .... = -ast /ra.1e!t
*P: 2ra.1e!t o//set = 0 bytes
*P: Ti1e to -ive = #34 seco!ds4ho(s
*P: Protoco- = 17 )5P+
*P: Header checks'1 = de"e
*P: &o'rce address = 1#".111.4#.1"% .oo/y
*P: esti!atio! address = 1#".111.49.3% co1ics
*P: 6o o(tio!s
*P:
5P: ----- 5P Header -----
5P:
5P: &o'rce (ort = 10##
5P: esti!atio! (ort = #049 )&'! RP7+
5P: 8e!.th = 1$0
5P: 7hecks'1 = 0949
5P:
RP7: ----- &56 RP7 Header -----
RP7:
RP7: Tra!sactio! id = "#143#913
RP7: Ty(e = 0 )7a--+
RP7: RP7 versio! = #
RP7: Pro.ra1 = 100003 )62&+% versio! = #% (roced're = 4
RP7: 7rede!tia-s: 2-avor = 1 )5!i0+% -e! = 7# bytes
RP7: Ti1e = 03-:'!-93 17:43:04
RP7: Host!a1e = .oo/y
RP7: 5id = 0% ;id = 1
RP7: ;ro'(s = 1 0 # 3 4 3 $ 7 " 9 1#
RP7: ,eri/ier : 2-avor = 0 )6o!e+% -e! = 0 bytes
RP7:
62&: ----- &'! 62& -----
62&:
62&: Proc = 4 )8ook '( /i-e !a1e+
62&: 2i-e ha!d-e = 00"000040000000#000<0000000#2#73
62&: 34$2<3#000<00000000000#37$92<#3
62&: 2i-e !a1e = a=k
62&: