Chapter 3: Transport Layer: Our Goals
Chapter 3: Transport Layer: Our Goals
our goals:
v understand v learn about Internet
principles behind transport layer protocols:
transport layer § UDP: connectionless
services: transport
§ multiplexing, § TCP: connection-oriented
demultiplexing reliable transport
§ reliable data transfer § TCP congestion control
§ flow control
§ congestion control
32
Transport Layer Outline
3.1 transport-layer 3.5 connection-oriented
services transport: TCP
3.2 multiplexing and § segment structure
demultiplexing § reliable data transfer
3.3 connectionless § flow control
transport: UDP § connection management
3.4 principles of reliable 3.6 principles of congestion
data transfer control
3.7 TCP congestion control
33
Transport layer
v Moving “down” a layer
v Current perspective:
§ Application is the boss….
§ Usually executing within the OS Kernel
§ The network layer is ours to command !!
34
Network layer (context)
v What it does: finds paths through network
§ Routing from one end host to another
v What it doesn’t:
§ Reliable transfer: “best effort delivery”
§ Guarantee paths
§ Arbitrate transfer rates
35
Transport services and protocols
application
transport
v provide logical communication network
data link
between app processes physical
§ Exports services to
application that network
layer does not provide
36
READ THIS IN TEXT
37
Why a transport layer?
many application
processes
browser
browser
mmedia
telnet
ftp
Application
Operating Transport
System
Network
IP Datalink
Physical
Drivers Datalink
+NIC Physical
Host A Host B
38
Why a transport layer?
many application
processes
Communication
between processes
browser
browser
mmedia
server
HTTP
telnet
telnet
ftp
ftp
at hosts
Transport Transport
IP IP
Datalink Datalink
Physical Communication Physical
between hosts
(128.4.5.6 ßà162.99.7.56)
Host A Host B
39
Quiz: Transport Layer Services
How many of these services might we provide at the transport layer ? Which ?
A: 4 or fewer
B: 5
C: 6
D: 7
E: All 8
40
Transport Layer Outline
3.1 transport-layer 3.5 connection-oriented
services transport: TCP
3.2 multiplexing and § segment structure
demultiplexing § reliable data transfer
3.3 connectionless § flow control
transport: UDP § connection management
3.4 principles of reliable 3.6 principles of congestion
data transfer control
3.7 TCP congestion control
41
Multiplexing/demultiplexing
multiplexing at sender:
handle data from multiple demultiplexing at receiver:
sockets, add transport header use header info to deliver
(later used for demultiplexing) received segments to correct
socket
application
Note: The network is a shared resource. It does not care about your applications, sockets, etc.
42
How demultiplexing works
v host receives IP datagrams 32 bits
§ each datagram has source IP source port # dest port #
address, destination IP
address
other header fields
§ each datagram carries one
transport-layer segment
§ each segment has source, application
destination port number data
v host uses IP addresses & (payload)
port numbers to direct
segment to appropriate TCP/UDP segment format
socket
43
Connectionless demultiplexing
v recall: created socket has v recall: when creating
host-local port #: datagram to send into
DatagramSocket mySocket1 UDP socket, must specify
= new DatagramSocket(12534);
§ destination IP address
§ destination port #
44
Connectionless demux: example
DatagramSocket
DatagramSocket serverSocket = new
DatagramSocket DatagramSocket
mySocket2 = new mySocket1 = new
DatagramSocket (6428); DatagramSocket
(9157); application (5775);
application P1 application
P3 P4
transport
transport transport
network
network link network
link physical link
physical physical
46
Revisiting TCP Sockets
Welcoming, port X
TCP handshake Socket
Client
Socket
Client Process 47
Connection-oriented demux: example
application
application P4 P5 P6 application
P3 P2 P3
transport
transport transport
network
network link network
link physical link
physical server: IP physical
address B
49
May I scan your ports?
http://netsecurity.about.com/cs/hackertools/a/aa121303.htm
v Servers wait at open ports for client requests
v Hackers often perform port scans to determine open,
closed and unreachable ports on candidate victims
v Several ports are well-known
§ <1024 are reserved for well-known apps
§ Other apps also use known ports
• MS SQL server uses port 1434 (udp)
• Sun Network File System (NFS) 2049 (tcp/udp)
v Hackers can use exploit known flaws with these known
apps
§ Example: Slammer worm exploited buffer overflow flaw in the
SQL server
http://www.auditmypc.com/
v How do you scan ports?
§ Nmap, Superscan, etc https://www.grc.com/shieldsup
50
Quiz: TCP Sockets
51
Quiz: TCP Sockets
A. Yes
B. No
52
Transport Layer Outline
3.1 transport-layer 3.5 connection-oriented
services transport: TCP
3.2 multiplexing and § segment structure
demultiplexing § reliable data transfer
3.3 connectionless § flow control
transport: UDP § connection management
3.4 principles of reliable 3.6 principles of congestion
data transfer control
3.7 TCP congestion control
53
UDP: User Datagram Protocol [RFC 768]
v “no frills,” “bare bones” Internet transport protocol
v “best effort” service, UDP segments may be:
§ lost
§ delivered out-of-order to app
v connectionless:
§ no handshaking between UDP sender, receiver
§ each UDP segment handled independently of
others
54
UDP: segment header
length, in bytes of
32 bits UDP segment,
source port # dest port # including header
length checksum
why is there a UDP?
v no connection
application establishment (which can
data add delay)
(payload)
v simple: no connection
state at sender, receiver
v small header size
UDP segment format v no congestion control:
UDP can blast away as
fast as desired
55
UDP checksum
• Goal: detect “errors” (e.g., flipped bits) in transmitted
segment
• Router memory errors
• Driver bugs
• Electromagnetic interference
sender: receiver:
v treat segment contents, v Add all the received
including header fields, as together as 16-bit integers
sequence of 16-bit integers v Add that to the checksum
v checksum: addition (one’s v If the result is not 1111
complement sum) of 1111 1111 1111, there are
segment contents
errors !
v sender puts checksum value
into UDP checksum field
56
Internet checksum: example
example: add two 16-bit integers
1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0
1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
wraparound 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1
sum 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0
checksum 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1
57
Quiz: Checksum
v A: Yes
v B: No
v C: Schrodinger’s Cat
58
Quiz: Checksum
59
UDP Applications
v Latency sensitive/time critical
v Quick request/response (DNS, DHCP)
v Network management (SNMP)
v Routing updates (RIP)
v Voice/video chat
v Gaming (especially FPS)
60
Quiz: Reliability over UDP?
61
Transport Layer Outline
3.1 transport-layer 3.5 connection-oriented
services transport: TCP
3.2 multiplexing and § segment structure
demultiplexing § reliable data transfer
3.3 connectionless § flow control
transport: UDP § connection management
3.4 principles of reliable 3.6 principles of congestion
data transfer control
3.7 TCP congestion control
62
Reliable Transport
@Sender @Receiver
§ send packets § wait for packets
63
Reliable Transport
64
TheThe
Two Generals
Two Problem
Generals Problem
Twoarmy
• vTwo armydivisions
divisions (blue)
(blue) surround
surround enemy
enemy(red)
(red)
Eachdivision
– §Each division led
led by
by aageneral
general
§ Both must agree when to simultaneously attack
– Both must agree when to simultaneously attack
§ If either side attacks alone, defeat
– If either side attacks alone, defeat
v Generals can only communicate via messengers
• Generals can may
§ Messengers onlyget
communicate via messengers
captured (unreliable channel)
– Messengers may get captured (unreliable channel)
65
TheThe
TwoTwo
Generals Problem
Generals Problem
•v How to coordinate?
How to coordinate?
–§ Send messenger:
Send messenger: “Attack
“Attack at dawn”
at dawn”
What ififmessenger
–§ What messenger doesn’t makemake
doesn’t it? it?
66
TheThe
Two Generals
Two Problem
Generals Problem
67
Quiz: Reliability
68
Engineering
v Concerns v Our toolbox
§ Message corruption § Checksums
§ Message duplication § Timeouts
§ Message loss § Acks and Nacks
§ Message reordering § Sequence numbering
§ Performance § Pipelining
send receive
side side
73
Reliable data transfer: getting started
we’ll:
v incrementally develop sender, receiver sides of
reliable data transfer protocol (rdt)
v consider only unidirectional data transfer
§ but control info will flow on both directions!
v use finite state machines (FSM) to specify sender,
receiver
event causing state transition
actions taken on state transition
state: when in this
“state” next state state state
uniquely determined 1 event
by next event 2
actions
74
Self Study
sender receiver
76
rdt2.0: channel with bit errors
v underlying channel may flip bits in packet
§ checksum to detect bit errors
v the question: how to recover from errors:
§ acknowledgements (ACKs): receiver explicitly tells sender
that pkt received OK
§ negative acknowledgements (NAKs): receiver explicitly tells
sender that pkt had errors
§ sender retransmits pkt on receipt of NAK
v new mechanisms in rdt2.0 (beyond rdt1.0):
§ error detection
§ feedback: control msgs (ACK,NAK) from receiver to
sender
77
Self Study
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
78
Self Study
rdt2.0: operation with no errors
rdt_send(data)
snkpkt = make_pkt(data, checksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
isNAK(rcvpkt)
Wait for Wait for rdt_rcv(rcvpkt) &&
call from ACK or udt_send(sndpkt) corrupt(rcvpkt)
above NAK
udt_send(NAK)
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
79
Self Study
rdt2.0: error scenario
rdt_send(data)
snkpkt = make_pkt(data, checksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
isNAK(rcvpkt)
Wait for Wait for rdt_rcv(rcvpkt) &&
call from ACK or udt_send(sndpkt) corrupt(rcvpkt)
above NAK
udt_send(NAK)
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
80
Global Picture of rdt2.0
sender receiver
data
data
ACK
81
rdt2.0 has a fatal flaw!
what happens if ACK/ handling duplicates:
NAK corrupted? v sender retransmits
v sender doesn’t know current pkt if ACK/NAK
what happened at corrupted
receiver!
v sender adds sequence
v can’t just retransmit: number to each pkt
possible duplicate
v receiver discards (doesn’t
deliver up) duplicate pkt
stop and wait
sender sends one packet,
then waits for receiver
response
82
Self Study
83
Self Study
extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(ACK, chksum)
udt_send(sndpkt)
84
rdt2.1: discussion
sender: receiver:
v seq # added to pkt v must check if received
v two seq. #’s (0,1) will packet is duplicate
suffice. Why? § state indicates whether
0 or 1 is expected pkt
v must check if received
seq #
ACK/NAK corrupted
v note: receiver can not
v twice as many states know if its last ACK/
§ state must NAK received OK at
“remember” whether sender
“expected” pkt should
have seq # of 0 or 1
85
Another Look at rdt2.1 Dotted line: erroneous transmission
Solid line: error-free transmission
sender receiver
data (0)
waiting for 0
NACK
sending # data (0
)
0
ACK
data (0
) waiting for 1
Duplicate Packet
ACK Discard !!
sending data (1
)
#1
waiting for 0
86
rdt2.2: a NAK-free protocol
v same functionality as rdt2.1, using ACKs only
v instead of NAK, receiver sends ACK for last pkt
received OK
§ receiver must explicitly include seq # of pkt being ACKed
v duplicate ACK at sender results in same action as
NAK: retransmit current pkt
87
rdt2.2: Example Dotted line: erroneous transmission
Solid line: error-free transmission
sender receiver
data (1
)
data (0
)
sending #
0
waiting for 0
88
Self Study
rdt2.2: sender, receiver fragments
rdt_send(data)
sndpkt = make_pkt(0, data, checksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
( corrupt(rcvpkt) ||
Wait for Wait for
ACK isACK(rcvpkt,1) )
call 0 from
above 0 udt_send(sndpkt)
sender FSM
fragment rdt_rcv(rcvpkt)
&& notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) && && isACK(rcvpkt,0)
(corrupt(rcvpkt) || Λ
has_seq1(rcvpkt)) Wait for receiver FSM
0 from
udt_send(sndpkt) below fragment
rdt_rcv(rcvpkt) && notcorrupt(rcvpkt)
&& has_seq1(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(ACK1, chksum)
udt_send(sndpkt) 89
Quiz: RDT 2.2 with only NACKs
v RDT 2.2 uses only ACKs and is robust against packet
errors. Would it be possible to implement RDT 2.2 with
only NACKs?
A. YES
B. NO
90
Quiz: Reliable Data Transfer
v If packets (and ACKs and NACKs) could be lost, which of
the following is true of rdt 2.1 (or 2.2)?
91
rdt3.0: channels with errors and loss
92
Self Study
rdt3.0 sender
rdt_send(data)
rdt_rcv(rcvpkt) &&
sndpkt = make_pkt(0, data, checksum) ( corrupt(rcvpkt) ||
udt_send(sndpkt) isACK(rcvpkt,1) )
rdt_rcv(rcvpkt) start_timer Λ
Λ Wait for Wait
for timeout
call 0from
ACK0 udt_send(sndpkt)
above
start_timer
rdt_rcv(rcvpkt)
&& notcorrupt(rcvpkt) rdt_rcv(rcvpkt)
&& isACK(rcvpkt,1) && notcorrupt(rcvpkt)
stop_timer && isACK(rcvpkt,0)
stop_timer
Wait Wait for
timeout for call 1 from
udt_send(sndpkt) ACK1 above
start_timer rdt_rcv(rcvpkt)
rdt_send(data) Λ
rdt_rcv(rcvpkt) &&
( corrupt(rcvpkt) || sndpkt = make_pkt(1, data, checksum)
isACK(rcvpkt,0) ) udt_send(sndpkt)
start_timer
Λ
93
rdt3.0 in action
sender receiver sender receiver
send pkt0 pkt0 send pkt0 pkt0
rcv pkt0 rcv pkt0
ack0 send ack0 ack0 send ack0
rcv ack0 rcv ack0
send pkt1 pkt1 send pkt1 pkt1
rcv pkt1 X
ack1 send ack1 loss
rcv ack1
send pkt0 pkt0
rcv pkt0 timeout
ack0 send ack0 resend pkt1 pkt1
rcv pkt1
ack1 send ack1
rcv ack1
send pkt0 pkt0
(a) no loss rcv pkt0
ack0 send ack0
95
Quiz: RDT 3.0 Performance
v Suppose we have a modest 8 Mbps link. Our RTT is
100ms, and we send 1024 byte (1K) segments. What is
our link utilization with a stop-and-wait protocol such as
RDT 3.0?
A. < 0.1 %
B. Approx. 0.1%
C. Approx 1%
D. 1-10%
E. > 10%
96
rdt3.0: stop-and-wait operation
sender receiver
first packet bit transmitted, t = 0
last packet bit transmitted, t = L / R
L/R 1ms
U sender = = (100+1)ms= 0.01 (i.e. 1%)
RTT + L / R
97
Transport Part 1: Summary
v Next Week:
v principles behind
§ Pipelined Protocols for
transport layer services: reliable data transfer
§ multiplexing, § TCP
demultiplexing • TCP Flow Control
§ reliable data transfer • TCF Connection
Management
• TCP Congestion
v UDP Control
Transport Layer 98