You are on page 1of 21

Transport Layer

Provides efficient, reliable, cost-effective service to processes in Application Layer using the services provided by the Network Layer. Provides a reliable service on top of the unreliable network.(is it needed?)

Reliable delivery service > Stream orientation as stream of bits. > Buffered Transfer > Virtual circuit connection > Unstructured stream - No record boundaries between data - The s and d must agree on stream format. > Full-Duplex connection

Reliable Stream Transport Service


Needed at Transport layer ??? Lower layers deliver packets out of order, with substantial delay, deliver duplicates where in packets can be lost or destroyed. Application programs need to provide error detection and recovery into each application program. Implementing a single general purpose solutions to the problems of providing reliable stream delivery for all application programs to use. Isolate application programs from the details of networking, and makes it possible to define a uniform interface for the stream transfer service.

Transmission Control Protocol


Reliable stream transport
Connection oriented (full duplex virtual circuit)
Conceptually place call, two ends communicate to agree on details After agreeing application notified of connection During transfer, ends communicate continuously to verify data received correctly When done, ends tear down the connection If UDP is like regular mail, TCP is like phone call

Provides buffering and flow control Takes care of lost packets, out of order, duplicates, long delays by Positive ACK Retransmission mechanism Isolates application program from network Hardware details Jargon
Segment = TCP packet Socket= source (address + port) + destination (address + port)
4

TCP FEATURES
Stream delivery Sending TCP
~ receives data as a stream of bytes from application process using sending buffer ~ make data to appropriate segments and transfer to network

Receiving TCP
~ receives segments using receiving buffer ~ reassemble segments to data and send data as a stream of bytes to application process

Sending and receiving buffers

The sending process and the receiving process may not produce and consume data at the same speed, TCP needs buffers for storage. Both the buffers might vary in their size.

TCP groups sequence of bytes into a group of packets called SEGMENTS of varying size( default segment size is 536 bytes).

Error control - By ACK and retransmission of the byte


numbered sequentially with a random start count value that lies between 0 to 232-1. - The sequence number of each segment is the number of the first byte carried in that segment. - The acknowledgement is indicated by sending the number of the next byte expected (indicating the bytes before that are received correctly). Positive acknowledgement (ACK) with retransmission Sender keeps record of each packet sent Sender awaits an ACK Sender starts timer when sends packet. Retransmission is done > when the ACK timer expired assuming the packet was lost. Receiver might receive duplicates > when the ACK is lost. > when network experience high delays.
7

Send Buffers: The application gives the TCP layer some data to send. The data is put in a send buffer, where it stays until the data is ACKd. it has to stay, as it might need to be sent again! The TCP layer wont accept data from the application unless (or until) there is buffer space.

ACKs
A receiver doesnt have to acknowledge every segment except ACK segments. (It can acknowledge many segments with a single ACK segment). Each ACK can also contain outgoing data (piggybacking). Acknowledgements are delayed when the receiver has no data to send and is receiving an in-order segment ,say x+1, after acknowledging the xth segment. Delay can be until the next segment arrives or until a period of time. Prevents extra traffic out of ACK segments. When the segments come in order the ACK sent immediately by sending at least one ACK per two in-order segments. This prevents the unnecessary retransmission of packets.
8

ACKs
Immediate ACK sent when an out-of-order segment with sequence number higher than the expected arrives. This indirectly leads to fast retransmission. As soon as a missing segment arrives an ACK is sent to report the missing segment received. Immediate ACK when a duplicate segment is received. If a sender doesnt get an ACK after some time limit it resends the data. Each ACK is sent with sequence number so that the sender shall correctly associate ACKs with packets.

TCP Segment format


0 4

16

24

31

Source port

Destinati port

Sequence number Acknowledgement number HL Res Ctr Checksum Window Urgent ptr Paddg
31

Options (if any) DATA


0

The unit of data transfer b/w 2 devices using TCP is a segment. Source/Dest port: TCP port numbers to Identify applications at both ends of connection Sequence number: Identify position in senders byte stream. A 32 bit field defines the number assigned to the first byte of the data contained in this segment. First two sequence numbers used for connection establishment. [ it is not segment number but the offset of the byte within the total bytes to be sent from a process.] 10

Acknowledgement: identifies the number of the byte the receiver of this segment expects to receive next. Hlen: specifies the length of the segment header in 32 bit multiples. If there are no options, the Hlen = 5 (20 bytes). Can be between 5 and 15. Reserved 6bit field reserved for future use, set to 0 Ctrl: used to determine segment purpose with 6 different fields such as URG,ACK, PSH, RST, SYN and FIN Window Size: Advertises how much data this station is willing to accept. Maximum size is 65,535 bytes (216-1) Checksum: Verifies the integrity of the TCP header and data. It is mandatory. Follows the same procedure as per UDP. Pseudo header is attached with Protocol field being 6. Urgent pointer: Used with the URG flag to indicate where the urgent data starts in the data stream. Typically used with a file transfer abort during FTP or when pressing an interrupt key in telnet. Options: Max of 40 bytes field. Used for window scaling, SACK, timestamps, max segment size etc.

11

TCP Connection Establishment


TCP uses a three-way handshake (four reduced to three) to open a connection: (1) ACTIVE OPEN: Client sends a segment with
SYN bit set * port number of client initial sequence number (ISN) of client

(2) PASSIVE OPEN: Server responds with a segment with


SYN bit set * initial sequence number of server ACK for ISN of client

(3) Client acknowledges by sending a segment with:


ACK ISN of server (* counts as one byte) - May send data. In general ACK for SYN does not carry any data. Hence do not consume Seq.no.
12

Three-Way Handshake to open a connection -example

aida.poly.edu

mng.poly.edu

Send SYN

SYN (Seq No = x)
y, A SYN (SeqNo = ckNo = x + 1 )

ACK+SYN

Send Confirm ation

(SeqNo = x

+1 , A c k N o

=y+1)

Initial sequence numbers (x, y) are chosen randomly (why??) Once connection established, data can flow in both directions, equally well. SYN FLOODING ATTACK DoS ??? and solution???

13

TCP Connection Termination


Each end of the data flow must be shut down independently (half-close) When one end terminates, the other party can continue sending data in the other direction. Four steps needed to close in both direction:
(1) X sends a FIN to Y (active close) (2) Y ACKs the FIN,
(at this time: Y can still send data to X)

(3) and Y sends a FIN to X (passive close) (4) X ACKs the FIN.

14

TCP close connection


Site 1
(App closes) Send FIN seq=x 1 Rcv ACK segment

Site 2

Rcv FIN segment Send ACK x=1 (inform app) 2 (app closes connection) Send FIN seq=y, ACK x+1 3 Receive ACK segment

Rcv FIN + ACK seg Send ACK y+1 4

App tells TCP to close, TCP sends remaining data & waits for ACK, then sends FIN 1 Site 2 TCP ACKs FIN, tells its application end of data 2 Site 2 sends FIN when its app closes connection (may be long delay (e.g. require human interaction). 3 Site 1 TCP ACKs FIN 4 ( signals 2 and 3 be combined hence made as 3-way close.)
15

Resetting Connections
Resetting connections is done by setting the RST flag When is the RST flag set?
Connection request arrives and no server process is waiting on the destination port Abort (Terminate) a connection due to abnormal situation. Causes the receiver to throw away buffered data. Receiver does not acknowledge the RST segment One side may discover that the TCP on the other side is idle for a long time. It sends an RST segment to destroy the connection.

16

PUSHING DATA - When delayed transmission and delayed delivery of data may not be acceptable by the application program. - To deliver the message as soon as possible without waiting for the window to be filled i.e., not to wait for more data to come. - TCP handles this by setting the push bit whenever an application program requests for a push operation.

17

Flow Control -Sliding Window


A sliding window is used to make transmission more efficient as well as to control the flow of data so that the destination does not become overwhelmed with data. TCPs sliding windows are byte oriented. Sender Window Receiver Window Sliding the Sender Window Expanding the sender Window Shrinking the sender Window Closing the Sender Window Size of the window = min (cwnd, rwnd) rwnd the value advertised by the receiver. cwnd Congestion window value determined by the network to avoid congestion.

TCP Buffers Both the client and server allocate buffers to hold incoming and outgoing data - The TCP layer does this. Both the client and server announce with every ACK how much buffer space remains (the Window field in a TCP segment is used for this ).

18

Flow Control -Sliding Window

closing

opening

As per the acknowledgements from the receiver the window is opened or closed but should not shrunk. Probing - The window shall be shut down by sending the window size as 0. But the sender however sends a segment with one byte of data to prevent deadlock. Silly Window Syndrome Problem Using the network capacity very inefficiently by sending of data in very small segments.

19

TIMERS USED in TCP


Retransmission dynamically set for every segment sent. Calculated based on RoundTripTime. Persistence To deal with zero-window size advertisement. Sender stops once it receives a zero window size from receiver and waits for an ACK from receiver with a new Window size. It sets this timer for ACK to come. - Whenever this timer expires, a probe signal is sent to the receiver. - It equals the Retransmission time. Continuously doubles till 60s and then every 60s a probe is sent until the window is reopened. Keep alive - used to prevent a long idle connection between two TCPs. - The server might wait for an inactive client for about two hours. - sends probes for every 75s - after 10 probes assumes the client is down and terminates the connection. Time-waited - During connection termination. - usually two times the expected life time of the segment.
20

TCP not fit in some applications:


As TCP is optimized for accurate delivery rather than timely delivery, TCP sometimes incurs relatively long delays (in the order of seconds) while waiting for out-of-order messages or retransmissions of lost messages, and it is not particularly suitable for real-time applications such as Voice over IP. For such applications, protocols like the Real-time Transport Protocol (RTP) running over the User Datagram Protocol (UDP) are usually recommended instead of TCP.

21

You might also like