Академический Документы
Профессиональный Документы
Культура Документы
Architecture
David E. Culler
CS162 Operating Systems and Systems Programming
http://cs162.eecs.berkeley.edu/
Lecture 32
Nov 12, 2014
Read: end-2-end
HW 5: Due today
Mid 2: 11/14
Proj 3: due 12/8
Review: Protocols
Review: Protocols
Q1: True _
X False _ Protocols specify the syntax and
semantics of communication
Q2: True _ False X_ Protocols specify the
implementation
Q3: True _ False _X Layering helps to improve
application performance
Q4: True _ False _X Best Effort packet delivery
ensures that packets are delivered in order
Q5: True _
X False _ In p2p systems a node is both a
client and a server
Q6: True _ False _X TCP ensures that each packet is
delivered within a predefined amount of time
11/12/14
Applications
NTP
UDP
IP
Transport
Waist
Data Link
Ethernet
Copper
SONET
Fiber
802.11
Radio
Physical
Application
Present.
Session
Transport
Network
Datalink
Physical
source
destination
IP network
11/12/14
11/12/14
Application
Transport
Network
Datalink
Physical
Network
Datalink
Physical
Application
Transport
Network
Datalink
Physical
Host A
Router
Host B
Physical Communication
Communication goes down to physical network
Then from network peer to peer
Then up to relevant layer
Application
Transport
Network
Datalink
Physical
Host A
11/12/14
Network
Datalink
Physical
Router
Application
Transport
Network
Datalink
Physical
Host B
Implications of Hourglass
Single Internet-layer module (IP):
Allows arbitrary networks to interoperate
Any network technology that supports IP can exchange packets
11/12/14
Network
Network
Layer
Layer
Physical
Physical
Layer
Layer
11/12/14
Trans.
Hdr.
Data
Transport
Transport
Layer
Layer
Net.
Hdr.
Trans.
Hdr.
Data
Network
Network
Layer
Layer
Net.
Hdr.
Trans.
Hdr.
Data
Datalink
Datalink
Layer
Layer
101010100110101110
Physical
Physical
Layer
Layer
Data
Transport
Transport
Layer
Layer
Datalink
Datalink
Layer
Layer
Data
Application
Application
Layer
Layer
Frame
Hdr.
Trans.
Hdr.
Data
Net.
Hdr.
Trans.
Hdr.
Data
Net.
Hdr.
Trans.
Hdr.
Data
101010100110101110
UCB CS162 Fa14 L32
Frame
Hdr.
10
Application
Present.
Session
Transport
Network
Service:
Datalink
Provide end-to-end communication between processes Physical
11
Application
Present.
Session
Transport
Network
Datalink
Physical
11/12/14
12
Application
Present.
Session
Transport
Network
Datalink
Physical
11/12/14
13
Socket API
Base level Network programming interface
Application
Socket
API
Transport
TCP
Network
11/12/14
UDP
IP
14
11/12/14
15
11/12/14
16
TCP Service
1) Open connection: 3-way handshaking
2) Reliable byte stream transfer from
(IPa, TCP_Port1) to (IPb, TCP_Port2)
11/12/14
17
Connecting Communication to
Processes
11/12/14
18
Recall: Sockets
Request Response Protocol
Client (issuesrequests)
n = read(rfd,rbuf,rmax);
wait
servicerequest
n = read(resfd,resbuf,resmax);
9/10/14
11/12/14
cs162 fa14 L5
19
11/12/14
20
write request
read request
read response
write response
11/12/14
21
Client Protocol
char*hostname;
intsockfd,portno;
structsockaddr_inserv_addr;
structhostent*server;
server=buildServerAddr(&serv_addr,hostname,portno);
/*CreateaTCPsocket*/
sockfd=socket(AF_INET,SOCK_STREAM,0)
/*Connecttoserveronport*/
connect(sockfd,(structsockaddr*)&serv_addr,sizeof(serv_addr)
printf("Connectedto%s:%d\n",server>h_name,portno);
/*CarryoutClientServerprotocol*/
client(sockfd);
/*Cleanupontermination*/
close(sockfd);
11/12/14
22
/*Acceptincomingconnection,obtaininganewsocketforit*/
consockfd=accept(lstnsockfd,(structsockaddr*)&cli_addr,
&clilen);
server(consockfd);
close(consockfd);
}
close(lstnsockfd);
11/12/14
23
11/12/14
26
Client (initiator)
SYN, Seq
Nu
m=x
listen()
Passive
Open
time
Active
Open connect()
11/12/14
27
Client (initiator)
Active
Open connect()
SYN, Seq
Nu
time
K, Seq
C
A
d
n
a
N
SY
11/12/14
m=x
x+1
=
k
c
A
d
n
Num = y a
ACK, Ack
=y+1
listen()
accept()
Passive
Open
allocate
buffer space
28
11/12/14
29
Close Connection
Goal: both sides agree to close the
connection
4-way connection tear down
Host 1
FIN
close
FIN ACK
data
timeout
FIN
Can retransmit FIN ACK
if it is lost
Host 2
FIN ACK
close
closed
closed
11/12/14
30
Reliable Transfer
Retransmit missing packets
Numbering of packets and ACKs
Do this efficiently
Keep transmitting whenever possible
Detect missing packets and retransmit quickly
Two schemes
Stop & Wait
Sliding Window (Go-back-n and Selective Repeat)
11/12/14
31
Missing ACKs
Receiver ACKs each packet
Sender detects a missing packet when seeing a gap in the
sequence of ACKs
Need to be careful! Packets and ACKs might be reordered
11/12/14
32
One-way latency (d): one way delay from sender and receiver
Sender
Receiver
1
RTT
ACK 1
2
RTT
RTT
RTT == 2*d
2*d
(if
(if latency
latency is
is
symmetric)
symmetric)
ACK 2
3
Time
11/12/14
33
RTT
ACK 1
2
RTT
ACK 2
3
Time
11/12/14
34
Receiver
1
RTT
ACK 1
2
RTT
ACK 2
3
Time
11/12/14
35
Receiver
1
RTT
ACK 1
2
RTT
ACK 2
3
Time
11/12/14
36
Receiver
1
RTT
timeou
t
ACK 1
Time
11/12/14
37
Sliding Window
window = set of adjacent sequence numbers
The size of the set is the window size
Assume window size is n
Let A be the last ACKd packet of sender without
gap; then window of sender = {A+1, A+2, , A+n}
Sender can send packets in its window
Let B be the last received packet without gap by
receiver, then window of receiver = {B+1,, B+n}
Receiver can accept out of sequence, if in window
11/12/14
38
{1}
{1, 2}
{1, 2, 3}
{2, 3, 4}
{3, 4, 5}
{4, 5, 6}
.
.
.
1
2
3
{}
{}
{}
.
.
.
4
5
6
Time
Sender
11/12/14
Out-o-seq packets
in receivers window
Receiver
UCB CS162 Fa14 L32
39
We want Throughput = C
Throughput = W*packet_size/RTT
C = W*packet_size/RTT
W = C*RTT/packet_size = 109bps*80*10-3s/(8000b) = 104 packets
Window
Window size
size ~~ Bandwidth
Bandwidth (Capacity),
(Capacity), delay
delay (RTT/2)
(RTT/2)
11/12/14
40
11/12/14
41
Timeout
Packet 4
1
2
3
4
5
6
Assume
packet 4 lost!
4
5
6
{}
{}
{}
NACK 4
NACK 4
Why doesnt sender
retransmit packet 4
here?
Sender
11/12/14
Out-o-seq packets
in receivers window
{5}
{5,6}
4 is
missing
{}
Receiver
42
11/12/14
43
Unacked packets
in senders window
{1}
{1, 2}
{1, 2, 3}
{2, 3, 4}
{3, 4, 5}
{4, 5, 6}
1
2
3
4
5
6
{4,5,6} 4
ACK 5
ACK 6
Time
{7}
7
Sender
11/12/14
Receiver
UCB CS162 Fa14 L32
44
Summary
TCP: Reliable Byte Stream
Open connection (3-way handshaking)
Close connection: no perfect solution; no way for two parties
to agree in the presence of arbitrary message losses
(Generals Paradox)
Reliable transmission
S&W not efficient for links with large capacity (bandwidth)
delay product
Sliding window more efficient but more complex
Flow Control
OS on sender and receiver manage buffers
Sending rate adjusted according to acks and losses
Receiver drops to slow sender on over-run
11/12/14
45