Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 3 Transport Layer TCP: connection oriented UDP: connectionless application presentation session transport network link physical.

Similar presentations


Presentation on theme: "Chapter 3 Transport Layer TCP: connection oriented UDP: connectionless application presentation session transport network link physical."— Presentation transcript:

1 Chapter 3 Transport Layer TCP: connection oriented UDP: connectionless application presentation session transport network link physical

2 Transport Layer: copyright J.F Kurose and K.W. Ross 3-2 Transport services and protocols r transport protocols run in end systems m send side: breaks app messages into segments, passes to network layer m rcv side: reassembles segments into messages, passes to app layer r more than one transport protocol available to apps m Internet: TCP and UDP application transport network data link physical application transport network data link physical logical end-end transport 5/6/2015 HtHt HnHn M segment HtHt datagram HtHt HnHn HlHl M message M HtHt M HnHn frame

3 Transport Layer: copyright J.F Kurose and K.W. Ross 3-3 Internet transport-layer protocols r reliable, in-order delivery (TCP) m congestion control m flow control m connection setup r unreliable, unordered delivery: UDP m no-frills extension of “best-effort” IP application transport network data link physical network data link physical network data link physical network data link physical network data link physical network data link physical network data link physical application transport network data link physical logical end-end transport 5/6/2015

4 Transport Layer: copyright J.F Kurose and K.W. Ross 3-4 Recall r TCP socket identified by 4-tuple: m source IP address m source port number m dest IP address m dest port number r receiving host uses all four values to direct segment to appropriate socket r Muxing/Demuxing r Server host may support many simultaneous TCP sockets: m each socket identified by its own 4-tuple r Web servers have different sockets for each connecting client m non-persistent HTTP will have different socket for each request 5/6/ Create a socket with the socket() system call 2.Bind socket to address using the bind() (port and ip address) 3.Listen for connections with the listen() system call 4.Accept a connection with the accept() system call. 5.Send and receive data over socket returned by accept 1.Create a socket with the socket() system call 2.Connect the socket to the address of the server using the connect() system call 3.Send and receive data.

5 Transport Layer: copyright J.F Kurose and K.W. Ross 3-5 UDP: User Datagram Protocol [RFC 768] r “no frills,” “bare bones” Internet transport protocol r “best effort” service, UDP segments may be: m lost m delivered out of order to app r connectionless: m no handshaking between UDP sender, receiver m each UDP segment handled independently of others Why is there a UDP? r no connection establishment (which can add delay) r simple: no connection state at sender, receiver r small segment header r no congestion control: UDP can blast away as fast as desired 5/6/2015

6 Ports r Well-known ports m 0 to 1023 are the well-known ports. m FTP 20/21, HTTP 80, Mail 25 r Registered ports r 1024 to are the registered ports and are assigned by Internet Assigned Numbers Authority (IANA) r Dynamic, private or ephemeral ports m 49152– /6/2015 Application Layer: copyright J.F Kurose and K.W. Ross 6 0 Well-known Registered Private 65535

7 Transport Layer: copyright J.F Kurose and K.W. Ross 3-7 UDP: more r often used for streaming multimedia apps m loss tolerant m rate sensitive r other UDP uses m DNS m SNMP r reliable transfer over UDP: add reliability at application layer m application-specific error recovery! source port #dest port # 32 bits Application data (message) UDP segment format length checksum Length, in bytes of UDP segment, including header 5/6/2015

8 Transport Layer: copyright J.F Kurose and K.W. Ross 3-8 UDP checksum Sender: r treat segment contents as sequence of 16-bit integers r checksum: addition (1’s complement sum) of segment contents r sender puts checksum value into UDP checksum field Receiver: r compute checksum of received segment r check if computed checksum equals checksum field value: m NO - error detected m YES - no error detected. But maybe errors nonetheless? More later …. Goal: detect “errors” (e.g., flipped bits) in transmitted segment 5/6/2015

9 Transport Layer: copyright J.F Kurose and K.W. Ross 3-9 Internet Checksum Example r Note m When adding numbers, a carryout from the most significant bit needs to be added to the result r Example: add two 16-bit integers wraparound sum checksum 5/6/2015

10 Transport Layer: copyright J.F Kurose and K.W. Ross 3-10 TCP 5/6/2015 r How ensure reliable data transfer?

11 Could acknowledge each packet r Based on old character-based protocols m ASCII/EBCDIC (ACK = 06/2E, NAK = 15/3D) m Acknowledgements (ACKs): receiver explicitly tells sender that pkt received OK m Negative acknowledgements (NAKs): receiver explicitly tells sender that pkt had errors m sender retransmits pkt on receipt of NAK r In packet might be a bit in the TCP header 5/6/2015Transport Layer: copyright J.F Kurose and K.W. Ross3-11

12 Transport Layer: copyright J.F Kurose and K.W. Ross 3-12 ACK/NAK has a fatal flaw! What happens if ACK/NAK corrupted? r sender doesn’t know what happened at receiver! r can’t just retransmit: possible duplicate Handling duplicates: r sender retransmits current pkt if ACK/NAK garbled r sender adds sequence number to each pkt r receiver discards (doesn’t deliver up) duplicate pkt Sender sends one packet, then waits for receiver response stop and wait 5/6/2015

13 Efficient? r Could go NAK-free protocol r instead of NAK, receiver sends ACK for last pkt received OK m receiver must explicitly include seq # of pkt being ACKed r duplicate ACK at sender results in same action as NAK: retransmit current pkt 5/6/2015Transport Layer: copyright J.F Kurose and K.W. Ross3-13

14 Transport Layer: copyright J.F Kurose and K.W. Ross 3-14 Cuts out one exchange: efficient? 5/6/2015

15 Transport Layer: copyright J.F Kurose and K.W. Ross 3-15 Pipelined protocols Pipelining: sender allows multiple, “in-flight”, yet-to- be-acknowledged pkts m range of sequence numbers must be increased m buffering at sender and/or receiver r Two generic forms of pipelined protocols: go-Back-N, selective repeat 5/6/2015

16 Transport Layer: copyright J.F Kurose and K.W. Ross 3-16 Pipelining Protocols Go-back-N: overview r sender: up to N unACKed pkts in pipeline r receiver: only sends cumulative ACKs m doesn’t ACK pkt if there’s a gap r sender: has timer for oldest unACKed pkt m if timer expires: retransmit all unACKed packets Selective Repeat: overview r sender: up to N unACKed packets in pipeline r receiver: ACKs individual pkts r sender: maintains timer for each unACKed pkt m if timer expires: retransmit only unACKed packet 5/6/2015

17 Transport Layer: copyright J.F Kurose and K.W. Ross 3-17 Go-Back-N Sender: r k-bit seq # in pkt header r “window” of up to N, consecutive unACKed pkts allowed r ACK(n): ACKs all pkts up to, including seq # n - “cumulative ACK” m may receive duplicate ACKs (see receiver) r timer for each in-flight pkt r timeout(n): retransmit pkt n and all higher seq # pkts in window 5/6/2015

18 Transport Layer: copyright J.F Kurose and K.W. Ross 3-18 GBN in action 5/6/2015

19 Transport Layer: copyright J.F Kurose and K.W. Ross 3-19 Selective Repeat r receiver individually acknowledges all correctly received pkts m buffers pkts, as needed, for eventual in-order delivery to upper layer r sender only resends pkts for which ACK not received m sender timer for each unACKed pkt r sender window m N consecutive seq #’s m again limits seq #s of sent, unACKed pkts 5/6/2015

20 Transport Layer: copyright J.F Kurose and K.W. Ross 3-20 Selective repeat: sender, receiver windows 5/6/2015

21 Transport Layer: copyright J.F Kurose and K.W. Ross 3-21 Selective repeat in action 5/6/2015

22 Transport Layer: copyright J.F Kurose and K.W. Ross 3-22 TCP seq. #’s and ACKs Seq. #’s: m byte stream “number” of first byte in segment’s data ACKs: m seq # of next byte expected from other side m cumulative ACK Q: how receiver handles out-of-order segments m A: TCP spec doesn’t say, - up to implementer Host A Host B Seq=42, ACK=79, data = ‘C’ Seq=79, ACK=43, data = ‘C’ Seq=43, ACK=80 User types ‘C’ host ACKs receipt of echoed ‘C’ host ACKs receipt of ‘C’, echoes back ‘C’ time simple telnet scenario 5/6/2015 Full Duplex

23 Transport Layer: copyright J.F Kurose and K.W. Ross 3-23 TCP segment structure source port # dest port # 32 bits application data (variable length) sequence number acknowledgement number Receive window Urg data pointer checksum F SR PAU head len not used Options (variable length) URG: urgent data (generally not used) ACK: ACK # valid PSH: push data now (generally not used) RST, SYN, FIN: connection estab (setup, teardown commands) # bytes rcvr willing to accept counting by bytes of data (not segments!) Internet checksum (as in UDP) 5/6/2015 length

24 Transport Layer: copyright J.F Kurose and K.W. Ross 3-24 TCP Round Trip Time and Timeout Q: how to set TCP timeout value? r longer than RTT m but RTT varies r too short: premature timeout m unnecessary retransmissions r too long: slow reaction to segment loss Q: how to estimate RTT?  SampleRTT : measured time from segment transmission until ACK receipt m ignore retransmissions  SampleRTT will vary, want estimated RTT “smoother”  average several recent measurements, not just current SampleRTT 5/6/2015

25 Transport Layer: copyright J.F Kurose and K.W. Ross 3-25 TCP Round Trip Time and Timeout EstimatedRTT = (1-  )*EstimatedRTT +  *SampleRTT r Exponential weighted moving average r influence of past sample decreases exponentially fast  typical value:  = /6/2015

26 Transport Layer: copyright J.F Kurose and K.W. Ross 3-26 Example RTT estimation: 5/6/2015

27 Transport Layer: copyright J.F Kurose and K.W. Ross 3-27 TCP Round Trip Time and Timeout Setting the timeout  EstimtedRTT plus “safety margin”  large variation in EstimatedRTT -> larger safety margin r first estimate of how much SampleRTT deviates from EstimatedRTT: TimeoutInterval = EstimatedRTT + 4*DevRTT DevRTT = (1-  )*DevRTT +  *|SampleRTT-EstimatedRTT| (typically,  = 0.25) Then set timeout interval: 5/6/2015

28 Transport Layer: copyright J.F Kurose and K.W. Ross 3-28 How does TCP ACK [RFC 1122, RFC 2581] 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 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 5/6/2015

29 Transport Layer: copyright J.F Kurose and K.W. Ross 3-29 Host A timeout Host B time X resend seq X2 seq # x1 seq # x2 seq # x3 seq # x4 seq # x5 ACK x1 triple duplicate ACKs 5/6/2015 Fast retransmit r time-out period often relatively long: m long delay before resending lost packet r detect lost segments via duplicate ACKs. m sender often sends many segments back-to- back m if segment is lost, there will likely be many duplicate ACKs for that segment

30 Transport Layer: copyright J.F Kurose and K.W. Ross 3-30 TCP Flow Control r receive side of TCP connection has a receive buffer: r speed-matching service: matching send rate to receiving application’s drain rate r app process may be slow at reading from buffer sender won’t overflow receiver’s buffer by transmitting too much, too fast flow control IP datagrams TCP data (in buffer) (currently) unused buffer space application process 5/6/2015

31 Transport Layer: copyright J.F Kurose and K.W. Ross 3-31 TCP Flow control: how it works (suppose TCP receiver discards out-of-order segments)  unused buffer space: = rwnd = RcvBuffer-[LastByteRcvd - LastByteRead]  receiver: advertises unused buffer space by including rwnd value in segment header (receive window)  sender: limits # of unACKed bytes to rwnd m guarantees receiver’s buffer doesn’t overflow IP datagrams TCP data (in buffer) (currently) unused buffer space application process rwnd RcvBuffer 5/6/2015

32 Transport Layer: copyright J.F Kurose and K.W. Ross 3-32 TCP Connection Management Recall: TCP sender, receiver establish “connection” before exchanging data segments r initialize TCP variables: m seq. #s  buffers, flow control info (e.g. RcvWindow ) r client: connection initiator Socket clientSocket = new Socket("hostname","port number"); r server: contacted by client Socket connectionSocket = welcomeSocket.accept(); Three way handshake: Step 1: client host sends TCP SYN segment to server m specifies initial seq # m no data Step 2: server host receives SYN, replies with SYNACK segment m server allocates buffers m specifies server initial seq. # Step 3: client receives SYNACK, replies with ACK segment, which may contain data 5/6/ way handshake or as "SYN-SYN-ACK" (or more accurately SYN, SYN-ACK, ACK). ASCII/EBCDIC Sync = 16/32

33 Transport Layer: copyright J.F Kurose and K.W. Ross 3-33 TCP Connection Management (cont.) Closing a connection: client closes socket: clientSocket.close(); Step 1: client end system sends TCP FIN control segment to server Step 2: server receives FIN, replies with ACK. Closes connection, sends FIN. client FIN server ACK FIN close closed timed wait 5/6/2015

34 Transport Layer: copyright J.F Kurose and K.W. Ross 3-34 TCP Connection Management (cont.) Step 3: client receives FIN, replies with ACK. m Enters “timed wait” - will respond with ACK to received FINs Step 4: server, receives ACK. Connection closed. client FIN server ACK FIN closing closed timed wait closed 5/6/2015

35 Transport Layer: copyright J.F Kurose and K.W. Ross 3-35 TCP congestion control: r goal: TCP sender should transmit as fast as possible, but without congesting network m Q: how to find rate just below congestion level r decentralized: each TCP sender sets its own rate, based on implicit feedback: m ACK: segment received (a good thing!), network not congested, so increase sending rate m lost segment: assume loss due to congested network, so decrease sending rate 5/6/2015

36 Transport Layer: copyright J.F Kurose and K.W. Ross 3-36 TCP congestion control: bandwidth probing r “probing for bandwidth”: increase transmission rate on receipt of ACK, until eventually loss occurs, then decrease transmission rate m continue to increase on ACK, decrease on loss (since available bandwidth is changing, depending on other connections in network) ACKs being received, so increase rate X X X X X loss, so decrease rate sending rate time TCP’s “sawtooth” behavior 5/6/2015

37 Transport Layer: copyright J.F Kurose and K.W. Ross 3-37 TCP throughput r Q: what’s average throughout of TCP as function of window size, RTT? m ignoring slow start r let W be window size when loss occurs. m when window is W, throughput is W/RTT m just after loss, window drops to W/2, throughput to W/2RTT. m average throughout:.75 W/RTT 5/6/2015

38 Transport Layer: copyright J.F Kurose and K.W. Ross 3-38 fairness goal: if K TCP sessions share same bottleneck link of bandwidth R, each should have average rate of R/K TCP connection 1 bottleneck router capacity R TCP connection 2 TCP Fairness 5/6/2015

39 Transport Layer: copyright J.F Kurose and K.W. Ross 3-39 Why is TCP fair? Two competing sessions: r Additive increase gives slope of 1, as throughout increases r multiplicative decrease decreases throughput proportionally R R equal bandwidth share Connection 1 throughput Connection 2 throughput congestion avoidance: additive increase loss: decrease window by factor of 2 congestion avoidance: additive increase loss: decrease window by factor of 2 5/6/2015

40 The End 5/6/2015 Transport Layer: copyright J.F Kurose and K.W. Ross 3-40


Download ppt "Chapter 3 Transport Layer TCP: connection oriented UDP: connectionless application presentation session transport network link physical."

Similar presentations


Ads by Google