Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 3 Transport Layer

Similar presentations


Presentation on theme: "Chapter 3 Transport Layer"— Presentation transcript:

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

2 Transport services and protocols
application transport network data link physical transport protocols run in end systems send side: breaks app messages into segments, passes to network layer rcv side: reassembles segments into messages, passes to app layer more than one transport protocol available to apps Internet: TCP and UDP logical end-end transport application transport network data link physical Ht Hn M segment datagram Hl message frame 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

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

4 Recall TCP socket identified by 4-tuple:
Create a socket with the socket() system call Bind socket to address using the bind() (port and ip address) Listen for connections with the listen() system call Accept a connection with the accept() system call. Send and receive data over socket returned by accept Create a socket with the socket() system call Connect the socket to the address of the server using the connect() system call Send and receive data. TCP socket identified by 4-tuple: source IP address source port number dest IP address dest port number receiving host uses all four values to direct segment to appropriate socket Muxing/Demuxing 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 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

5 UDP: User Datagram Protocol [RFC 768]
“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 Why is there a UDP? no connection establishment (which can add delay) simple: no connection state at sender, receiver small segment header no congestion control: UDP can blast away as fast as desired 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

6 Ports Well-known ports Registered ports
Well-known 1023 1024 Registered 49151 49152 Private 65535 Well-known ports 0 to 1023 are the well-known ports. FTP 20/21, HTTP 80, Mail 25 Registered ports 1024 to are the registered ports and are assigned by Internet Assigned Numbers Authority (IANA) Dynamic, private or ephemeral ports 49152–65535 From wiki The Internet Assigned Numbers Authority (IANA) is the entity that oversees global IP address allocation, autonomous system number allocation, root zone management in the Domain Name System (DNS), media types, and other Internet Protocol-related symbols and numbers. IANA is a department operated by the Internet Corporation for Assigned Names and Numbers, also known as ICANN. [1] Well-known ports The port numbers in the range from 0 to 1023 are the well-known ports. They are used by system processes that provide widely-used types of network services. On Unix-like operating systems, a process must execute with superuser privileges to be able to bind a network socket to an IP address using one of the well-known ports. Registered ports The range of port numbers from 1024 to are the registered ports. They are assigned by IANA for specific service upon application by a requesting entity.[1] On most systems registered ports can be used by ordinary users. Dynamic, private or ephemeral ports The range 49152– above the registered ports - contains dynamic or private ports that cannot be registered with IANA. This range is used for custom or temporary purposes and for automatic allocation of ephemeral ports. 4/14/2017 Application Layer: copyright J.F Kurose and K.W. Ross

7 UDP: more other UDP uses often used for streaming multimedia apps
loss tolerant rate sensitive other UDP uses DNS SNMP reliable transfer over UDP: add reliability at application layer application-specific error recovery! 32 bits source port # dest port # Length, in bytes of UDP segment, including header length checksum Application data (message) Just four fields, 2 bytes each (remember, this is not network layer) UDP segment format 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

8 UDP checksum Goal: detect “errors” (e.g., flipped bits) in transmitted segment Sender: treat segment contents as sequence of 16-bit integers checksum: addition (1’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 …. 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

9 Internet Checksum Example
Note When adding numbers, a carryout from the most significant bit needs to be added to the result Example: add two 16-bit integers Kurose and Ross forgot to say anything about wrapping the carry and adding it to low order bit Puts in header cause not all links are guaranteed to have link layer error checking (CRC) wraparound sum checksum 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

10 TCP How ensure reliable data transfer? 4/14/2017
Transport Layer: copyright J.F Kurose and K.W. Ross

11 Could acknowledge each packet
Based on old character-based protocols ASCII/EBCDIC (ACK = 06/2E, NAK = 15/3D) 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 In packet might be a bit in the TCP header 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

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

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

14 Cuts out one exchange: efficient?
4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

15 Pipelined protocols 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 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

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

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

18 GBN in action 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

19 Selective Repeat 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 again limits seq #s of sent, unACKed pkts 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

20 Selective repeat: sender, receiver windows
4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

21 Selective repeat in action
4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

22 simple telnet scenario
TCP seq. #’s and ACKs Seq. #’s: byte stream “number” of first byte in segment’s data ACKs: 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 implementer Host A Host B User types ‘C’ Seq=42, ACK=79, data = ‘C’ host ACKs receipt of ‘C’, echoes back ‘C’ Full Duplex Seq=79, ACK=43, data = ‘C’ host ACKs receipt of echoed ‘C’ Seq=43, ACK=80 time simple telnet scenario 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

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

24 TCP Round Trip Time and Timeout
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 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

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

26 Example RTT estimation:
4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

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

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 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 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

29 Fast retransmit time-out period often relatively long:
Host A Host B 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 for that segment seq # x1 seq # x2 seq # x3 X ACK x1 seq # x4 seq # x5 ACK x1 ACK x1 ACK x1 triple duplicate ACKs resend seq X2 timeout time 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

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

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

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

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 close closed timed wait 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

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

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

36 TCP congestion control: bandwidth probing
“probing for bandwidth”: increase transmission rate on receipt of ACK, until eventually loss occurs, then decrease transmission rate 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 loss, so decrease rate X X X TCP’s “sawtooth” behavior sending rate X time 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

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

38 TCP Fairness 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 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

39 Why is TCP fair? Two competing sessions:
Additive increase gives slope of 1, as throughout increases multiplicative decrease decreases throughput proportionally R equal bandwidth share loss: decrease window by factor of 2 congestion avoidance: additive increase Connection 2 throughput Start at bott, R line is where loss begins (1+2throughput constant) Throughput of 1 higher than 2 at first zig, decrease in rate (window) is proportional Conn 2 loses less loss: decrease window by factor of 2 congestion avoidance: additive increase Connection 1 throughput R 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross

40 The End 4/14/2017 Transport Layer: copyright J.F Kurose and K.W. Ross


Download ppt "Chapter 3 Transport Layer"

Similar presentations


Ads by Google