470 likes | 621 Views
Lecture 8. Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012. CS3516: These slides are generated from those made available by the authors of our text. 3.4 principles of reliable data transfer 3.2 multiplexing and demultiplexing
E N D
Lecture 8 Computer Networking: A Top Down Approach 6th edition Jim Kurose, Keith RossAddison-WesleyMarch 2012 CS3516: These slides are generated from those made available by the authors of our text. Introduction
3.4 principles of reliable data transfer 3.2 multiplexing and demultiplexing 3.3 connectionless transport: UDP 3.5 connection-oriented transport: TCP segment structure reliable data transfer flow control connection management Lecture 8 outline TransportLayer
pipelining: sender allows multiple, “in-flight”, yet-to-be-acknowledged pkts range of sequence numbers must be increased buffering at sender and/or receiver two generic forms of pipelined protocols: go-Back-N, selective repeat Pipelined protocols TransportLayer
Pipelining: increased utilization sender receiver first packet bit transmitted, t = 0 last bit transmitted, t = L / R first packet bit arrives RTT last packet bit arrives, send ACK last bit of 2nd packet arrives, send ACK last bit of 3rd packet arrives, send ACK ACK arrives, send next packet, t = RTT + L / R 3-packet pipelining increases utilization by a factor of 3! TransportLayer
Go-back-N: sender can have up to N unacked packets in pipeline receiver only sends cumulative ack doesn’t ack packet if there’s a gap sender has timer for oldest unacked packet when timer expires, retransmit all unacked packets Selective Repeat: sender can have up to N unack’ed packets in pipeline rcvr sends individual ack for each packet sender maintains timer for each unacked packet when timer expires, retransmit only that unacked packet Pipelined protocols: overview TransportLayer
k-bit seq # in pkt header “window” of up to N, consecutive unack’ed pkts allowed Go-Back-N: sender • ACK(n): ACKs all pkts up to, including seq # n - “cumulative ACK” • may receive duplicate ACKs (see receiver) • timer for oldest in-flight pkt • timeout(n): retransmit packet n and all higher seq # pkts in window TransportLayer
Wait GBN: sender extended FSM rdt_send(data) if (nextseqnum < base+N) { sndpkt[nextseqnum] = make_pkt(nextseqnum,data,chksum) udt_send(sndpkt[nextseqnum]) if (base == nextseqnum) start_timer nextseqnum++ } else refuse_data(data) L base=1 nextseqnum=1 timeout start_timer udt_send(sndpkt[base]) udt_send(sndpkt[base+1]) … udt_send(sndpkt[nextseqnum-1]) rdt_rcv(rcvpkt) && corrupt(rcvpkt) rdt_rcv(rcvpkt) && notcorrupt(rcvpkt) base = getacknum(rcvpkt)+1 If (base == nextseqnum) stop_timer else start_timer TransportLayer
ACK-only: always send ACK for correctly-received pkt with highest in-order seq # may generate duplicate ACKs need only remember expectedseqnum out-of-order pkt: discard (don’t buffer): no receiver buffering! re-ACK pkt with highest in-order seq # GBN: receiver extended FSM default udt_send(sndpkt) rdt_rcv(rcvpkt) && notcurrupt(rcvpkt) && hasseqnum(rcvpkt,expectedseqnum) L Wait extract(rcvpkt,data) deliver_data(data) sndpkt = make_pkt(expectedseqnum,ACK,chksum) udt_send(sndpkt) expectedseqnum++ expectedseqnum=1 sndpkt = make_pkt(expectedseqnum,ACK,chksum) TransportLayer
0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 GBN in action sender receiver sender window (N=4) send pkt0 send pkt1 send pkt2 send pkt3 (wait) receive pkt0, send ack0 receive pkt1, send ack1 receive pkt3, discard, (re)send ack1 X loss rcv ack0, send pkt4 rcv ack1, send pkt5 0 1 2 3 4 5 6 7 8 receive pkt4, discard, (re)send ack1 ignore duplicate ACK receive pkt5, discard, (re)send ack1 pkt 2 timeout send pkt2 send pkt3 send pkt4 send pkt5 rcv pkt2, deliver, send ack2 rcv pkt3, deliver, send ack3 rcv pkt4, deliver, send ack4 rcv pkt5, deliver, send ack5 TransportLayer
receiver individually acknowledges all correctly received pkts buffers pkts, as needed, for eventual in-order delivery to upper layer sender only resends pkts for which ACK not received sender timer for each unACKed pkt sender window N consecutive seq #’s limits seq #s of sent, unACKed pkts Selective repeat TransportLayer
Selective repeat: sender, receiver windows TransportLayer
I’m going to keep telling you this TCP joke until you get it. I’m going to keep telling you this TCP joke until you get it. I’m going to keep telling you this TCP joke until you get it. I’m going to keep telling you this TCP joke until you get it. TransportLayer
data from above: if next available seq # in window, send pkt timeout(n): resend pkt n, restart timer ACK(n)in [sendbase,sendbase+N]: mark pkt n as received if n smallest unACKed pkt, advance window base to next unACKed seq # receiver sender Selective repeat pkt n in [rcvbase, rcvbase+N-1] • send ACK(n) • out-of-order: buffer • in-order: deliver (also deliver buffered, in-order pkts), advance window to next not-yet-received pkt pkt n in [rcvbase-N,rcvbase-1] • ACK(n) otherwise: • ignore TransportLayer
0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 Selective repeat in action sender receiver sender window (N=4) send pkt0 send pkt1 send pkt2 send pkt3 (wait) receive pkt0, send ack0 receive pkt1, send ack1 receive pkt3, buffer, send ack3 X loss rcv ack0, send pkt4 rcv ack1, send pkt5 0 1 2 3 4 5 6 7 8 receive pkt4, buffer, send ack4 record ack3 arrived receive pkt5, buffer, send ack5 pkt 2 timeout send pkt2 record ack4 arrived rcv pkt2; deliver pkt2, pkt3, pkt4, pkt5; send ack2 record ack4 arrived Q: what happens when ack2 arrives? TransportLayer
example: seq #’s: 0, 1, 2, 3 window size=3 pkt0 pkt1 0 1 2 3 0 1 2 pkt2 0 1 2 3 0 1 2 0 1 2 3 0 1 2 pkt3 X 0 1 23 0 1 2 pkt0 will accept packet with seq number 0 (a) no problem pkt0 pkt1 0 1 2 3 0 1 2 pkt2 0 1 2 3 0 1 2 X 0 1 2 3 0 1 2 X timeout retransmit pkt0 X pkt0 will accept packet with seq number 0 0 1 23 0 1 2 (b) oops! 0 1 2 3 0 1 2 0 1 2 3 0 1 2 0 1 2 3 0 1 2 0 1 2 3 0 1 2 0 1 2 3 0 1 2 0 1 2 3 0 1 2 0 1 2 3 0 1 2 receiver window (after receipt) sender window (after receipt) Selective repeat:dilemma • receiver sees no difference in two scenarios! • duplicate data accepted as new in (b) Q: what relationship between seq # size and window size to avoid problem in (b)? receiver can’t see sender side. receiver behavior identical in both cases! something’s (very) wrong! TransportLayer
Selective Repeat requires a Timer for each packet. How are you going to do that? You only have one timer. A similar problem occurs if three roommates want to get up at different times in the morning, and they only have one alarm clock. Selective Repeat TransportLayer
Q: how to set TCP timeout value? longer than RTT but RTT varies too short: premature timeout, unnecessary retransmissions too long: slow reaction to segment loss Q: how to estimate RTT? SampleRTT: measured time from segment transmission until ACK receipt ignore retransmissions SampleRTT will vary, want estimated RTT “smoother” average several recent measurements, not just current SampleRTT This is from Section 3.5 TCP round trip time, timeout TransportLayer
time (seconds) TCP round trip time, timeout EstimatedRTT = (1- )*EstimatedRTT + *SampleRTT • exponential weighted moving average • influence of past sample decreases exponentially fast • typical value: = 0.125 RTT:gaia.cs.umass.edutofantasia.eurecom.fr RTT (milliseconds) sampleRTT EstimatedRTT TransportLayer
timeout interval: EstimatedRTT plus “safety margin” large variation in EstimatedRTT -> larger safety margin estimate SampleRTT deviation from EstimatedRTT: TCP round trip time, timeout DevRTT = (1-)*DevRTT + *|SampleRTT-EstimatedRTT| (typically, = 0.25) TimeoutInterval = EstimatedRTT + 4*DevRTT estimated RTT “safety margin” TransportLayer
3.4 principles of reliable data transfer 3.2 multiplexing and demultiplexing 3.3 connectionless transport: UDP 3.5 connection-oriented transport: TCP segment structure reliable data transfer flow control connection management Lecture 8 outline TransportLayer
handle data from multiple sockets, add transport header (later used for demultiplexing) use header info to deliver received segments to correct socket multiplexing at sender: demultiplexing at receiver: Multiplexing/demultiplexing application P1 P2 application application socket P4 P3 transport process network transport transport link network network physical link link physical physical TransportLayer
host receives IP datagrams each datagram has source IP address, destination IP address each datagram carries one transport-layer segment each segment has source, destination port number host uses IP addresses & port numbers to direct segment to appropriate socket How demultiplexing works 32 bits source port # dest port # other header fields application data (payload) TCP/UDP segment format TransportLayer
recall: created socket has host-local port #: DatagramSocket mySocket1 = new DatagramSocket(12534); when host receives UDP segment: checks destination port # in segment directs UDP segment to socket with that port # Connectionless demultiplexing • recall: when creating datagram to send into UDP socket, must specify • destination IP address • destination port # IP datagrams with same dest. port #, but different source IP addresses and/or source port numbers will be directed to same socket at dest TransportLayer
source port: 9157 dest port: 6428 source port: ? dest port: ? source port: ? dest port: ? source port: 6428 dest port: 9157 Connectionless demux: example DatagramSocket serverSocket = new DatagramSocket (6428); DatagramSocket mySocket2 = new DatagramSocket (9157); DatagramSocket mySocket1 = new DatagramSocket (5775); application application application P1 P3 P4 transport transport transport network network network link link link physical physical physical TransportLayer
TCP socket identified by 4-tuple: source IP address source port number dest IP address dest port number demux: receiver uses all four values to direct segment to appropriate socket server host may support many simultaneous TCP sockets: each socket identified by its own 4-tuple web servers have different sockets for each connecting client non-persistent HTTP will have different socket for each request Connection-oriented demux TransportLayer
source IP,port: A,9157 dest IP, port: B,80 source IP,port: C,5775 dest IP,port: B,80 source IP,port: B,80 dest IP,port: A,9157 source IP,port: C,9157 destIP,port: B,80 Connection-oriented demux: example application application application P4 P5 P6 P3 P3 P2 transport transport transport network network network link link link physical physical physical server: IP address B host: IP address C host: IP address A three segments, all destined to IP address: B, dest port: 80 are demultiplexed to different sockets TransportLayer
source IP,port: A,9157 dest IP, port: B,80 source IP,port: C,9157 destIP,port: B,80 source IP,port: C,5775 dest IP,port: B,80 source IP,port: B,80 dest IP,port: A,9157 Connection-oriented demux: example threaded server application application application P4 P3 P3 P2 transport transport transport network network network link link link physical physical physical server: IP address B host: IP address C host: IP address A TransportLayer
3.4 principles of reliable data transfer 3.2 multiplexing and demultiplexing 3.3 connectionless transport: UDP 3.5 connection-oriented transport: TCP segment structure reliable data transfer flow control connection management Lecture 8 outline The problem with UDP jokes: I don’t get half of them. I dressed up as a UDP packet. I don’t think anyone got it, but I couldn’t tell. A UDP packet walks into a bar without a checksum. Nobody cares. TransportLayer
“no frills,”“bare bones” Internet transport protocol “best effort” service, UDP segments may be: lost delivered out-of-order to app connectionless: no handshaking between UDP sender, receiver each UDP segment handled independently of others UDP: User Datagram Protocol [RFC 768] • UDP use: • streaming multimedia apps (loss tolerant, rate sensitive) • DNS • SNMP • reliable transfer over UDP: • add reliability at application layer • application-specific error recovery! TransportLayer
no connection establishment (which can add delay) simple: no connection state at sender, receiver small header size no congestion control: UDP can blast away as fast as desired UDP: segment header length, in bytes of UDP segment, including header 32 bits source port # dest port # checksum length why is there a UDP? application data (payload) UDP segment format TransportLayer
sender: treat segment contents, including header fields, as sequence of 16-bit integers checksum: addition (one’s complement sum) of segment contents sender puts checksum value into UDP checksum field receiver: compute checksum of received segment check if computed checksum equals checksum field value: NO - error detected YES - no error detected. But maybe errors nonetheless? More later …. UDP checksum Goal: detect “errors” (e.g., flipped bits) in transmitted segment TransportLayer
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 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1 wraparound sum checksum Note: when adding numbers, a carryout from the most significant bit needs to be added to the result TransportLayer
3.4 principles of reliable data transfer 3.2 multiplexing and demultiplexing 3.3 connectionless transport: UDP 3.5 connection-oriented transport: TCP segment structure reliable data transfer flow control connection management Lecture 8 outline TransportLayer
full duplex data: bi-directional data flow in same connection MSS: maximum segment size connection-oriented: handshaking (exchange of control msgs) inits sender, receiver state before data exchange flow controlled: sender will not overwhelm receiver point-to-point: one sender, one receiver reliable, in-order byte steam: no “message boundaries” pipelined: TCP congestion and flow control set window size TCP: Overview RFCs: 793,1122,1323, 2018, 2581 TransportLayer
TCP segment structure 32 bits URG: urgent data (generally not used) counting by bytes of data (not segments!) source port # dest port # sequence number ACK: ACK # valid acknowledgement number head len not used receive window U A P R S F PSH: push data now (generally not used) # bytes rcvr willing to accept checksum Urg data pointer RST, SYN, FIN: connection estab (setup, teardown commands) options (variable length) application data (variable length) Internet checksum (as in UDP) TransportLayer
sequence numbers: byte stream “number” of first byte in segment’s data acknowledgements: seq # of next byte expected from other side cumulative ACK Q: how receiver handles out-of-order segments A: TCP spec doesn’t say, - up to implementor outgoing segment from sender source port # source port # dest port # dest port # incoming segment to sender sequence number sequence number acknowledgement number acknowledgement number rwnd rwnd checksum checksum urg pointer urg pointer A TCP seq. numbers, ACKs window size N • sender sequence number space sent ACKed usable but not yet sent sent, not-yet ACKed (“in-flight”) not usable TransportLayer
TCP seq. numbers, ACKs Host B Host A User types ‘C’ Seq=42, ACK=79, data = ‘C’ host ACKs receipt of ‘C’, echoes back ‘C’ Seq=79, ACK=43, data = ‘C’ host ACKs receipt of echoed ‘C’ Seq=43, ACK=80 simple telnet scenario TransportLayer
TCP creates rdt service on top of IP’s unreliable service pipelined segments cumulative acks single retransmission timer retransmissions triggered by: timeout events duplicate acks let’s initially consider simplified TCP sender: ignore duplicate acks ignore flow control, congestion control TCP reliable data transfer TransportLayer
data rcvd from app: create segment with seq # seq # is byte-stream number of first data byte in segment start timer if not already running think of timer as for oldest unacked segment expiration interval: TimeOutInterval timeout: retransmit segment that caused timeout restart timer ack rcvd: if ack acknowledges previously unacked segments update what is known to be ACKed start timer if there are still unacked segments TCP sender events: TransportLayer
data received from application above create segment, seq. #: NextSeqNum pass segment to IP (i.e., “send”) NextSeqNum = NextSeqNum + length(data) if (timer currently not running) start timer ACK received, with ACK field value y if (y > SendBase) { SendBase = y /* SendBase–1: last cumulatively ACKed byte */ if (there are currently not-yet-acked segments) start timer else stop timer } timeout retransmit not-yet-acked segment with smallest seq. # start timer TCP sender (simplified) L wait for event NextSeqNum = InitialSeqNum SendBase = InitialSeqNum TransportLayer
Seq=100, 20 bytes of data ACK=120 ACK=100 TCP: retransmission scenarios Host B Host B Host A Host A SendBase=92 Seq=92, 8 bytes of data Seq=92, 8 bytes of data timeout timeout ACK=100 X Seq=92, 8 bytes of data Seq=92, 8 bytes of data SendBase=100 SendBase=120 ACK=100 ACK=120 SendBase=120 lost ACK scenario premature timeout TransportLayer
Seq=100, 20 bytes of data timeout ACK=100 ACK=120 TCP: retransmission scenarios Host B Host A Seq=92, 8 bytes of data X Seq=120, 15 bytes of data cumulative ACK TransportLayer
TCP ACK generation[RFC 1122, RFC 2581] TCP receiver action delayed ACK. Wait up to 500ms for next segment. If no next segment, send ACK immediately send single cumulative ACK, ACKing both in-order segments immediately send duplicate ACK, indicating seq. # of next expected byte immediate send ACK, provided that segment starts at lower end of gap event at receiver arrival of in-order segment with expected seq #. All data up to expected seq # already ACKed arrival of in-order segment with expected seq #. One other segment has ACK pending arrival of out-of-order segment higher-than-expect seq. # . Gap detected arrival of segment that partially or completely fills gap TransportLayer
time-out period often relatively long: long delay before resending lost packet detect lost segments via duplicate ACKs. sender often sends many segments back-to-back if segment is lost, there will likely be many duplicate ACKs. TCP fast retransmit TCP fast retransmit if sender receives 3 ACKs for same data (“triple duplicate ACKs”), resend unacked segment with smallest seq # • likely that unacked segment lost, so don’t wait for timeout (“triple duplicate ACKs”), TransportLayer
timeout ACK=100 ACK=100 ACK=100 ACK=100 TCP fast retransmit Host B Host A Seq=92, 8 bytes of data Seq=100, 20 bytes of data X Seq=100, 20 bytes of data fast retransmit after sender receipt of triple duplicate ACK TransportLayer