Department of Electrical and Computer Engineering University of Waterloo

Chapter 5: Transport Layer
ECE 610 – Winter 2013

Dr. Mohamed Mahmoud

5.1 Introduction

5.2 Connectionless transport: UDP

5.3 Connection-oriented transport: TCP



- Transport layer: end-to end layer – not implemented in the intermediate routers - At sender: receives message from application layer – encapsulate it in segment and send to network layer – segmentation: breaks application messages into segments (smaller pieces) and passes them to network layer - At receiver: decapsulate segments - deliver messages to application layer


g.Provide logical communication processes running on different hosts between application . .The transport layer is responsible for process-to-process data messages between applications (e. file transfer. the Web) 5 . email.Two processes communicate together .Types of data deliveries ..2 .

The transport layer oversees the end-to-end (source-todestination) delivery of an entire message maintains communication streams between applications. .Duties of the transport layer 1. even those belonging to a single message.End-to-End Delivery . 5-3 .The network layer treats each packet as an independent entry.

.Addressing . .IP address: Network level protocols need to know which two computers within an internet are communicating.Prevent the sender from overrunning the receiver 5-4 each process .Port number: Transport level protocols need to know which upper-layer protocols are communicating. .2.Flow control .MAC address: Data link level protocols need to know which two computers within a network are communicating. .Multiple processes may be run at a host must have a unique identifier 3.Flow control at this layer is performed end-to-end rather than across a single link.

.Sequence Control .Error Control .4.Aspects of reliable data transfer 1.Unlike error handling at the data link layer: this is end-toend error control 2.Reliable Delivery: .Error detection and retransmission.At sender: An application layer’s messages is divided into segments 5-5 .

4.At receiver: the original message is reassembled .Each segment carries a field that indicates whether it is the final segment or middle segment of a transmission.Loss Control .Sequence numbers allow the receiver to identify and discard duplicate segments.Duplication Control . 5-6 . .Sequence numbers allow the receiver’s transport layer protocol to identify any missing segments and request redelivery.. This number indicates the order for reassembly.Transport layer adds a sequence number at each segment.Segments should be properly reassembled at the receiver . 3.

machine crashed..Sender may send several segments destined to different processes.Handling process-to process communication cannot be handled by the data link layer because nodes would not know what happened two or more hops ahead of them. . Multiplexing: the segments should have enough information to be distributed to the correct processes. packets dropped. e.5. link failed… Only ends can be sure of receipt/non-receipt of a message 5-7 .Multiplexing .Demultiplexing is needed at the receiver to distribute the segments to the correct processes Note: .g.

Internet transport-layer protocols: TCP.Congestion control: throttle sender when network overloaded .TCP Transmission Control Protocol .Flow control: sender won’t overwhelm receiver . UDP 1.Reliable.Full-Duplex: data can flow in both directions simultaneously . in-order delivery .Stream-of-bytes service: sends and receives a stream of bytes – not messages 5-8 .TCP uses acknowledgements and retransmissions – detect corrupted and missing data makes sure all packets are successfully received .Segmentation and re-assemble segments in the right order .Connection-oriented: establish connection before data transfer .

in order for the data to be useful.Examples: WWW using HTTP.Applications require 100% reliable data transfer to be effective all of the sent data arrive at the destination in its original condition. File transfer using FTP 5-9 . Any missing data could cause a corrupt communication that is either incomplete or unreadable. . Electronic mail using SMTP.Motivation: IP layer provides a best-effort service .need to build a reliable layer on top of IP TCP Applications .

.UDP advantages .2.No flow control and no congestion control .corrupted – duplicated – missing. .No delay for connection establishment – UDP sends data without contacting the end host first . unordered data transfer – received data can be out of order .10 .Unreliable (“best-effort”)..No congestion control: UDP can blast away as fast as desired 5 .Connectionless: No connection establishment before data transfer .UDP requires less overhead and offers faster performance than TCP .UDP: User Datagram Protocol .Full duplex .

Simple: no connection state at sender and receiver – No allocation of buffers. it would only create a momentary disruption in the stream. This may appear as distortion in the image but may not even be noticeable to the user. 5 .Used for applications that can tolerate small amount of packet loss and require low delay to be effective: Multimedia applications. Internet telephony.For example..11 . real-time-video conferencing.Small packet header size: only 8 bytes . Audio . if one or two segments of a video stream fail to arrive. parameters easier to handle many clients at once UDP Applications 1.

2. .This does not mean that applications that use UDP are always unreliable. and therefore it does not need TCP to guarantee the message delivery 5 . It simply means that these functions are not provided by the Transport layer protocol and must be implemented elsewhere if required. like Domain Name System (DNs). .DNS will simply retry the request if it does not receive a response.TCP sends several packets of overhead before one single useful data message to establish a connection.12 . .An application that sends just one message.

e. .Processes on two hosts communicate over network by sending and receiving messages. ..g.Network-core devices do not run user applications 5 . web server software communicates with browser software .Write programs that run on end systems.Processes communicating across network Creating a network application .13 .No need to write software for network-core devices application .Process: An instance of a program in execution.

Socket = API (application host or programming interface) 5 .A socket is the interface between the application layer and the transport layer within a host. .Applications on end systems allows for rapid applications development and propagation .Socket is similar to a file descriptor – controls a communication end point .Create sockets with port number 6600: DatagramSocket mySocket1 = new DatagramSocket(6600). .The process receives messages from.Socket API is a library in C functions.14 . . and sends messages into the network through its socket ..Sockets are the programming interface used to build network applications over the internet. .

Operating system: Deliver data to the destination socket based on the destination port number .Socket analogous to door . Maximum segment size. .Delivering the data: division of labor .15 .Network: Deliver data packet to the destination host based on the destination IP address .Application: Read data from and write data to the socket 5 ..Sending process shoves message out door and relies on transport infrastructure on other side of door to transport message to socket at receiving process . starting sequence number of segment).Programmers can select which transport layer protocol (UDP or TCP) to be used by the application and select few transportlayer parameters (maximum buffer size.

Operating system enforces uniqueness .Port numbers are unique on each host cannot use same port number twice with same address. it needs to know which process should receive the message. the operating system can’t demultiplex packets correctly .16 .When a host receives a message.A port address: A unique number assigned to an application process as an address to receive or send data. . .Port numbers: 16-bit integer 5 . otherwise.Addressing processes .Port number uniquely identifies the socket .A single host may run several processes have identifier process must .

e. 21 FTP. 53 DNS. 1812 RADIUS Authentication protocol.Client applications can be programmed to request a connection to one of these ports and its associated service.Port numbers are divided in three ranges: 1. port 80 for Web and port 25 for e-mail. 443 Secure HTTP(HTTPS) . 1863 MSN messengers 5 . 2.g.Not controlled by IANA but registers and lists the uses of these ports e. 80 HTTP.iana.17 ...Registered Ports (numbers 1024 to 49151) .Well-known ports (numbers 0 to 1023) Popular applications have well-known ports assigned by the Internet Assigned Numbers Authority (IANA) See http://www.

Transport layer at the receiving host delivers data to the socket . server port) . e.3.g. 192. client port. server IP. short-lived ports Client picks an unused ephemeral (i.168.There should be a unique identifier for each socket.Dynamic or private ports (numbers 49152 to 65535) Can be assigned dynamically to client applications when initiating a connection. .A socket pair for a TCP connection is the four-tuple that defines the a TCP connection (client IP.12:80 identifies each endpoint of a connection .2.Socket identifier is called socket address = IP address and port number..A socket pair uniquely identifies the traffic between the hosts 5 .e.. temporary) port .18 . listening socket .3.3.3..115:21} connection request to 10.While server processes have static port numbers assigned to them.115 server {*:21. port 21 10. 10.0.115 server {*:21.19. 1) TCP server (ftp) with a passive open on port 21 10.137 client {10. clients dynamically chooses a port number for each conversation.19. *:*} 5 . *:*} listening socket 2) Connection request from client to server 10.

137:4915 2. 10. *:*} listening socket server child {10.3.137:49152} connected socket Main server spawns a child to handle each new connection 5 .115:21} . 10.115 server {*:21.0.3) Concurrent server has child handle client.137 client {

115:21} client {10. 10.21 .0.115 server {*:21. 10.137:49153} listening socket connected socket connected socket 5 .} 10.137:49152} server child { *:*} server child {10.137:49153 .19. client {10.19.3. Second client connection with same server.

wait to hear from a client (passive open). associate local address and port with the socket. do stuff to handle the request (e.Typical client program:1.Close the socket Typical server program:1.g. read data from the socket 3. accept an incoming connection from a client 2. send data to the socket 3.Prepare to communicate: create a socket.Exchange data with the client over new socket: Receive data from the socket. determine server address and port number. initiate the connection to the server 2.Exchange data with the server: Write data to the socket.Prepare to communicate: create a socket.. get a file).Close the socket 5 .22 .

23 ...… but don’t actually establish . in case several try to communicate at once .Upon accepting a new client -… create a new socket for the communication 5 .Allowing a backlog of waiting clients .Prepare to accept connections .Hearing from multiple clients .Create a socket for each client ..… until hearing from a client .Passive open .Servers differ from clients .

Multiplexing and demultiplexing 5 .24 .

25 .Multiplexing (at the sending node): the process of encapsulating messages from different applications sockets with the header information and pass the segments to the network layer .Downloading a web page while transferring data through FTP and two telnet sessions (provide a bidirectional interactive text-oriented communication) are also running ..Transport layer receives packets from network layer for all four processes 5 .The header information are later used for demultiplexing .Example: Suppose the following is running on the same computer: .Demultiplexing (at the receiving node): The process of delivering the received data segment to the correct application (socket) .

but different source IP addresses and/or source port numbers will be directed to same socket at destination 5 .Each IP datagram has source IP address. and one transport-layer segment.26 .Host uses IP addresses & port numbers to direct segment to appropriate socket . destination IP address. dest IP address. source port number. Each segment has source and destination port numbers.TCP socket is identified by 4-tuple: (source IP address. dest port number) receiving host uses all four values to direct segment to appropriate socket . .UDP: directs segment to socket with that the segment’s port number IP datagrams with same destination port number.How demultiplexing works .

port: B.port: B.27 .port: A.port: C.port: B.80 .9157 dest IP.Three segments.80 host: IP address C source IP.80 dest IP.Connection-oriented demultiplexing: example application application P4 P5 P6 application P3 transport transport network link physical network link physical P2 transport network link physical P3 server: IP address B host: IP address A source IP.port: A.port: C. all destined to IP address: B.80 source IP. destination port: 80 are demultiplexed to different sockets 5 .5775 dest IP.9157 source IP.port: B.9157 dest IP.

All other requests are stored in a queue waiting for service.A server application that uses UDP serves only ONE request at a time. . 5 .Connectionless demultiplexing: example Port: 9157 application Port: 6428 application Port: 9266 application P3 transport network link physical source port: 6428 dest port: 9157 P1 transport network link physical P4 transport network link physical source port: 6428 dest port: 9266 source port: 9157 dest port: 6428 source port: 9266 dest port: 6428 .28 .

2 Connectionless transport: UDP 5.1 Introduction 5.Outline 5.3 Connection-oriented transport: TCP .

arrive out of order. duplicated.Application writes a message to a UDP socket .It does not add anything to the services of IP except to provide process-to-process communication. . or corrupted .29 . under some conditions.A UDP segment can be lost. because it does nothing 5 .Unreliable “best effort” service has no flow and error control .Reliable transfer over UDP: add reliability at application layer .which is then encapsulated in a UDP datagram .UDP: User Datagram Protocol .which is then sent to destination .each segment is handled independently of others .UDP runs up to 40% faster than TCP.Connectionless: no handshaking between sender and receiver .

Destination port: the destination port and is required. including header. .Total Length (in bytes) of UDP segment.30 .Source port: the sending port and the port to reply to if needed. If not used. 5 . It is between 8 and 65. .535 bytes (8 byte header + 65527 bytes of data). then it should be zero.User datagram format .A fixed-size header of 8 bytes .

Checksum: detect “errors” (e. What is the total length of the user datagram? d. Example: The following is a UDP header in hexadecimal format: CB84000D001C001C a.31 . – Checked at receiver drop packet if error is detected . What is the source port number? b..g.. Is the packet directed from a client to a server or vice versa? 5 . flipped bits) in the entire UDP segment. What is the destination port number? c. What is the length of the data? e.Optional: The value sent for the checksum field is all 0s to show that the checksum is not calculated.

e. The length of the data is the length of the whole packet minus the length of the header.Solution a. c. d. The third four hexadecimal digits (001C)16 define the length of the whole UDP packet as 28 bytes. 5 . The source port number is the first four hexadecimal digits (CB84)16 or 52100. Since the destination port number is 13 (well-known port). b. or 28 – 8 = 20 bytes. The destination port number is the second four hexadecimal digits (000D)16 or 13. the packet is from the client to the server.32 .

Outline 5.1 Introduction 5.3 Connection-oriented transport: TCP .2 Connectionless transport: UDP 5.

.TCP sends segments – destination application reads bytes .Full duplex: bi-directional data flow in same connection 5 . .. it creates a virtual connection between two TCPs to send data.Byte-stream: source application writes bytes .33 .TCP uses flow and error control mechanisms at the transport level.TCP is a connection-oriented protocol.Each segment encapsulated in IP datagram .

in-order delivery of a stream of bytes .34 .TCP is reliable byte stream protocol that can create a connection between any pair of processes on any pair of Internet hosts 5 . one receiver .Congestion control: Prevents the sender from overloading network switches and routers .Allows two application programs to form a connection. ..Reliable. send data in either direction.Flow control: keep sender from overrunning receiver Receiver limits the amount of data the sender can send at any time . and then terminate the connection.Point-to-point one sender.

Source port (16 bits): identifies the sending port .3.Destination port (16 bits): identifies the receiving port 5 .1 TCP segment format .35 .5.

5 .36 . TCP host updates the sequence numbers to point to the position of the segment’s first data in the byte stream . It is the sequence number of the actual first data byte.Contains a number that uniquely identifies the segment .Each TCP host self-assigns its own initial sequence number (ISN) .ISN is set during connection establishment.. .Acknowledgement number field (32 bits): indicates the next expected sequence number from the other side of the communications.Sequence number field (32 bits): . .The identifier enables TCP receivers to identify when parts of a communication stream are missing.For each segment.

Sequence Number/Acknowledgement Number Fields are used to be sure each packet has arrived.Host A ISN (initial sequence number) Sequence number = 1st byte TCP Data TCP HDR Ack sequence number = next expected byte TCP HDR TCP Data Host B .37 . place segments in order. allow a specific segment to be acknowledged 5 .

Reserved (6 bits): for future use and should be set to zero .Checksum (16 bits): . . Space remaining in receiver’s buffer and willing to accept.Enables receiver to check if there is an error in the segment.A window size of zero indicates that a sender should stop transmitting — the receiver’s TCP buffer is full 5 .Window size (16 bits): ..Advertised window size in bytes.Header length (Hlen): header length in 4-byte words .38 .The checksum is computed on the contents of the TCP header and data . .value ranges from 5 to 15 . Number of bytes sender can send before receiving an ACK.

. and terminating a connection .PSH (push request): Do not delay delivery of data Inform receiver to send data to application as soon as possible – bypass buffering and pass data to upper layer.Six 1-bit flags: play an important role in establishing.sender at end of byte stream .SYN (Synchronization Request): Synchronize segment for setup .FIN: Final segment for teardown .End of Transmission Marker 5 .ACK(acknowledgment): ACK sequence number is valid . .RST(Reset Request): Reset the connection (reject or abnormal termination) .URG (urgent pointer): The urgent pointer should be examined .39 . maintaining.synchronize sequence numbers during connection.

5 .40 .

maximum window is 65.41 .Needed for high-speed connections or long delay paths 5 .Options and padding: Rarely used . .Maximum segment (MSS) Option: the maximum amount of data receiver is willing to accept in each TCP segment .535 bytes (corresponding field in TCP header occupies 16 bits) -it can be scaled (left-shifted) by 0-14 bits providing a maximum of 65.Window Scale Option .Padding (or dummy bits) may be needed to bring options to 32-bit boundary .up to 40 bytes of options. . then this 16-bit field is an offset from the sequence number indicating the last urgent data byte.535 * 214 bytes (one gigabyte) .Urgent pointer (16 bits): if the URG flag is set..

the hosts send signals to end the connection.2 Connection management .3.Connection termination: When data transfer is finished.Connection-oriented data delivery has three stages: 1.Connection establishment: ensure that both hosts are ready and know the initial sequence numbers.Data transfer 3. Connection establishment Data transfer Connection termination B A time 5 .42 .5. 2.

Acknowledgement of confirmation 5 .43 .1.Connection request 2.Three-way handshaking Responding computer Requesting computer A B 1.TCP Connection establishment .Connection confirmation 3.

1- Connection request message: - Objectives: 1- Ensure the destination host is available, has an active service and is accepting requests on the destination port number 2- Tells the destination that the initiator wants to open a connection and its initial sequence number and port number - Connection request from A to B, send a self-assigned initial sequence number (e.g., 8000) - SYN = 1 (remaining flags are 0) - Source port (e.g., 2352), destination port (e.g., 80 for http) 2- Connection confirmation message: - B tells A it accepts, and is ready to hear the next byte, B’s Initial Sequence Number

5 - 44

- Upon receiving this packet, A can start sending data with A’s initial sequence number + 1 - ACK for message 1 (ACK flag = 1), ACK sequence= 8000+1 - Connection request from B to A (SYN = 1) - Send initial sequence number (e.g., 1500) - The acknowledgement number is that of the next segment expected - it implicitly acknowledges all segments with smaller numbers (cumulative ACK) 3- Acknowledgement of confirmation message: - A tells B it is ok to start sending - Upon receiving this message, B can start sending data with B’s initial sequence number +1 - ACK for message 2 (ACK flag = 1), ACK sequence =1500+1 - The message may contain data
5 - 45

- Client: connection initiator - user clicks on a hypertext link - browser creates a socket and does a “connect” to trigger the operating system to transmit a SYN
Socket clientSocket = new Socket("hostname", "port number");

- Server: contacted by client
Socket connectionSocket = welcomeSocket.accept();

- What if the SYN packet gets lost, e.g., packet is lost inside the network, or server rejects the packet (e.g., listen queue is full)? No SYN-ACK arrives: sender sets a timer and wait for the SYN-ACK and retransmits the SYN if needed - How should the TCP sender set the timer? Sender has no idea how far away the receiver is - hard to guess a reasonable length of time to wait - some TCPs use a 5 - 46 default of 3 or 6 seconds

47 . number of the first byte in the packet ACK the data receiver from the server The next expected byte 5 .2.Data Transfer The seq.

Segment sent when: 1. but times out. 5 .. 2.Receiver: TCP checks that data has been received. Segment full (MSS bytes. default 352). Not full.Sender: TCP transfers data as a continuous stream of bytes.48 . . or 3. -Receiver: sends an acknowledgement giving the sequence number of the byte that it expects next. “Pushed” by application.

3.49 .Connection termination Using three-way handshaking Requesting computer Responding computer A Disconnection request B closing closing closed Disconnection confirmation Acknowledgement of confirmation closed 5 .

FIN = 1 .Disconnection request message: (from A to B) .ACK = 1. 3.Acknowledgement of confirmation: from B to A.1.Finish (FIN) to close and receive remaining bytes . it sends TCP FIN control segment to server with finish flag (FIN) =1 .The segment consumes one sequence number if it does not carry data.Once client has sent all of the outstanding bytes.50 . ACK = 1 5 .Disconnection confirmation message: (from B to A) .Reset (RST) to close and not receive remaining bytes 2.The FIN segment consumes one sequence number if it does not carry data. .Client closes socket by invoking: clientSocket.close(). .

B closes it later after finishing data transmission 5 .51 .A sends all its data and closes the connection .Half-close .

Out of order segments could cause the FIN segment to arrive before the last data segment a connection may be closed before finishing data transfer .When the system that the transport entity is running on fails and subsequently restarts. reset (RST) segments can be used to close connections quickly (an abnormal termination). 5 .Failure Recovery . the state information of all active connections is lost . the next sequence number after the last one is assigned to FIN .Still active side of a half-open connection can close the connection using a keep-alive timer .each side must acknowledge the FIN of the other using this sequence number. .In some cases.52 .To avoid this.Affected connections become half open because the side that did not fail does not realize the problem .

. local address and port number.Netstat .Shows protocol.Unexpected connections may mean there is a security problem.53 . foreign address and port number. 5 .

Sliding window 5 .Flow control: sender won’t overrun receiver’s buffer by transmitting too much.A sliding window is used to make data transmission more efficient (pipelining see chapter 3) and to control the flow of data so that the receiver does not become overwhelmed.54 .5. too fast .3 TCP flow control .3.

Speed-matching service: matching the sending rate to the receiving application’s drain rate 5 .RcvWindow: amount of spare room in buffer .RcvBuffer: size of TCP Receive buffer .Receiver’s buffer: .55 .Application process may remove data from TCP socket buffer slower than the TCP receiver is delivering (sender is sending) .Or receiver host may be shared by many processes and cannot consume data received at the rate that sender host sends. .

RcvWindow: Defines the amount of data that can be transmitted without receiving an acknowledgement..56 . . 5 .Receiver: explicitly informs sender of (dynamically changing) amount of free buffer space RcvWindow field in TCP ACK segment .The initial window size is determined during the session startup via the three-way handshake. .Sender: keeps the amount of transmitted and unACKed data less than most recently received RcvWindow . .Guarantees receiving buffer doesn’t overflow .Receiver can controls how many bytes are sent The receiver can increase or decrease the size of the sender window.Sliding window at the transport layer is byte oriented rather than frame oriented.

An acknowledgment can expand the size of the sender window based on the sequence number of the acknowledged data segment. .57 ..Flow control is achieved by forcing the sender to wait for an acknowledgment Receiver Side Advertised Window: Shrinks as data arrives and grows as the application consumes data 5 . .The sender’s window size is dynamic and controllable by receiver.

host B.Q: What is the value of the receiver window (RcvWindow) for host A if the receiver. Host B can receive only 4000 bytes of data before overflowing its buffer.reduce the retransmissions in retransmissions avoid waste of resources Flow Control ≠ Congestion control congestion control is about preventing too many 5 . Host B advertises this value in its next segment to A Flow Control can improve reliability and performance of TCP transmission 1.58 losses inside the network . has a buffer size of 5000 bytes and 1000 bytes of received and unprocessed data? A: The value of RcvWindow = 5000 − 1000 = 4000.Prevent buffer overflow Reduce the chance of dropping segments at destination if the buffer is full – avoid waste of resources 2.

The receiver can temporarily shut down the window .59 .Window size = 0 receiver asks the sender to stop transmitting data 5 ..

Sign up to vote on this title
UsefulNot useful