• TCP is a transport layer protocol (and software implemenation) whose primary function is to enhace the quality of service
(QOS) provided by the network layer.
- Packets can be lost or destroyed.
- Packets can be delivered out of order.
- There can be a substantial delay and even duplicates.
• For applications that send large volumes of data from one computer to another, it is not optimal to have apps programmers build error detection and recovery into each application.
• We need a mechanism that provides a reliable delivery service.
TCP is that mechanism !
1
Stream Orientation:
• Stream delivery service on destination passes to receiver exact same sequence of bytes that the sender passed to it on the source.
Virtual Circuit Connection:
• Conceptually one application places a “call” that must be accepted by the other Protocol s/ware on both sides communicate and verify that both sides are ready.
Once details have been settled, each side informs the application that a “connection” has been established.
Buffered Transfer:
• App streams data to the protocol s/ware. Protocol may divide stream into packets as it sees fit.
2
1
• How does TCP provide reliable delivery when the underlying network offers only unreliable packet delivery ?
• Uses a mechanism called “ positive acknowledgement with retransmission ”.
• Recipient sends back an acknowledgement (ACK) to the source as it receives data.
Sender keeps a record of each packet sent and waits for an acknowledgement before sending the next.
Sender also starts a timer and retransmits a packet if the timer expires before the acknowledgement arrives
3
Send Packet 1
Receive Packet 1
Send ACK 1
Receive ACK 1
Send Packet 2
Receive ACK 2
Receive Packet 2
Send ACK 2
Send Packet 1
(Start Timer)
ACK would normally arrive by this time
Receive ACK 1
Cancel Timer
Packet Lost
Packet should arrive
ACK should be sent
Retrans PK 1
Receive Packet 1
Send ACK 1
4
2
• A simple positive acknowledgement protocol wastes a substantial amount of network bandwidth because it delays sending a new packet until it receives acknowledgement of the previous one.
• Sliding window protocol allows the sender to send multiple packets before waiting for an acknowledgement.
• The no. of packets that can be unacknowledged at any one time is constrained by the windows size
Performance thus depends on window size and speed at which network accepts packets
5
• Window is a sequence of packets to be transmitted.
• Protocol can transmit all packets within the window.
• Number of packets that can be unacknowledged at any one time is constrained by the window size.
6
3
7
• TCP Protocol specifies:
•
- Format of data and acknowledgements exchanged by computers.
- Procedures to be used to ensure data arrives correctly.
- How to distinguish among multiple destinations on a machine.
- How to recover from errors (eg lost packets, duplicates)
- How machines initiate a stream transfer, and how they agree when it is complete.
8
4
• Uses protocol port numbers to identify the ultimate destination within a machine.
• TCP is devised around a connection abstraction - virtual circuits between machines.
Thus the port number alone is not enough to identify the circuit.
• The TCP endpoint in a machine is a combination of the host id and the protocol port number. (host, port)
• The connection (or virtual endpoint) is made up of two endpoints.
A typical TCP connection descriptor :
(193.1.56.73 , 225) and (193.1.56.16 , 23)
Is a unique port number required for each connection to a TCP service?
9
• Because TCP is connection oriented, both endpoints must agree to participate.
• One app performs a passive open function (“I will accept calls”)
• One app performs an active open. (“I am placing a call”)
• Data is then streamed in a sequence of bytes to be transferred.
This is further divided into segments.
• TCP uses a sliding window mechanism to:
- Maximise network usage.
- Provide end-to-end flow control .
10
5
• Each acknowledgement specifies how may bytes have been received.
It also contains a window advertisement - essentially the receivers current buffer size.
• This provides reliable transfer and flow control.
Essential in an internet environment where datagrams pass across networks and routers of varying speeds and capacity.
End-to-end flow control.
11
12
6
• Connection established via a three-way “handshake”.
• Server executes LISTEN and ACCEPT Primitives
• Client executes CONNECT
- Specifies IP address and port, max TCP segment, opt data
- CONNECT sends TCP segment with syn bit on and ack bit off
• Server receiving the TCP segment checks to see if a process has done a listen at the port specified.
If not send reply with rst bit set to on - reject connection.
• If a process is listen at a port, TCP segment is passed to that process. It may accept or reject the connection request.
Accept : syn bit and ack bit both on.
• Finally , client acknowledges that a connection has been established
13
• Connection is closed using a modified three-way handshake and the close operation.
• To close its half of the connection the sender sends a TCP segment (TPDU) with the fin bit set.
Receiver acknowledges it and connection is closed (on that end)
• Data may continue to flow in the other direction until that sender initiates a close operation.
• When both connections have been closed, TCP software on both ends deletes its record of the connection.
• Like UDP, TCP has some predefined “well-known port numbers” EG : Port 80 for www server.
14
7