Data And Computer Communications - Transport Layer
Transport Layer
Transport Layer is responsible to data delivery. We need to maintain a stable data transfer. Many functions of the transport layer is similar to those offered by the data link layer. The key differenece is, Data link layer manages transport in a single network, while transport layer manages traffic across an internetwork (end-to-end delivery).
- Packetizing
- Addressing - Port Number to idenify the process running in the two-end-system
- Connection control - TCP
- Reliability - Flow control(make sure reciever no overflow) and Error control
- Congestion control - deal with congestion(too much traffic) in the network
In Process-to-Process Delivery:
- Sender side: breaks application messages into segments, passes to network layer
- Receiver side: reassembles segments into messages, passes to application layer
Service Access Points
Delivery of messages is not simply between machines, but between applications running on the two machines
- Transport layer supports the data transfer for each of them through service access points
Port number
To identify the end applications individually, transport layer will assign an service-point address, or port number, to each communicating application (Service Access Points)
- Port number is 16-bit integer
- Port number ensures delivery to the correct process
- In the Internet model, IP address and the port number are used for process-to-process delivery
- Socket address = IP address + port number
- E.g. 152.138.50.1:80
- There is Source Port number and Destination Port number.
IANA (Internet Assigned Number Authority) has divided the port number into three range
- Well-known ports: assigned and controlled by IANA
- Registered ports: Registered with IANA to prevent duplication
- Dynamic ports: used by any process
Some Well-known ports:
Connection Control at Transport Layer
The transport layer protocol can be connectionless or connection-oriented.
Therefore we have 2 different protocols.
Connectionless
We don’t need to setup any connection before we send data (just like datagram)
- No connection establishment or connection release
- Segments may arrive out of sequence
- No acknowledgement
Connection-oriented
- Establish connection before data transfer
- Release connection at the end
- Segments arrive in order
Error Control at Transport Layer
The Link layer doesn’t deal with problem occured at the routers.
- So we need to error check in End to End basis
Flow Control at Transport Layer
Flow Control at Transport layer is typically done with Sliding Window Mechanism.
- window size may be variable
- Advertised by the receiver in the acknowledgment message, according to the available buffer size
- we use window size to adjust the sending rate
Internet Transport-Layer Protocols
As mentioned , we have 2 different protocols.
Internet: UDP and TCP
User Datagram Protocol (UDP)
- Connectionless
- Unreliable (No Flow and error Control, No Congestion Control, No Connection Control)
Transmission Control Protocol (TCP)
- Connection-oriented
- Flow and error Control
- Congestion Control
- Connection Control
UDP vs TCP
- UDP doesn’t require ACK but TCP require ACK
- TCP is more reliable
- UDP has less overhead than TCP in terms of:
- header size – hence UDP is more suitable for very small datagrams
- time for connection control – no need to set up a connection before data transmission
User Datagram Protocol (UDP)
- Connectionless
- Data sequence not guaranteed
- Reception not guaranteed
- Data can be sent to multiple destinations and received from multiple destinations
Some application uses of UDP
- Route updating protocols
- Real time data
UDP Header Fields
The 8 bytes Header contains:
- Source port number
- Destination port number
- Total length
- Checksum (optional) - detect error in both header and data
We can see, the UDP Frame is so simple that It has no control fields.
Transmission Control Protocol (TCP)
TCP is a reliable but complex transport protocol.
- Reliable
- Connection-oriented
- a logical connection must be established between the sender and receiver
- Stream-oriented
- sending process delivers data as a stream of bytes
- receiving process obtains data as a stream of bytes
- Use of Sliding Window to control the sending of data
- In Transport layer the basic unit is segment
Basic Operation of TCP
At the sending side, TCP divides a long stream of data into small data units called a Segment.
- Segments are carried across networks, encapsulated inside IP datagrams
- Note that IP may divide a TCP segment into multiple IP fragments
At the receiving side, TCP collects each segment as it comes in, and reorders the segments based on their sequence numbers
- Recall that IP provides a best-effort datagram delivery service that may arrive out of order and/or with errors
TCP Header Fields
- Source port address (16 bits)
- Define the application program in the source computer
- Destination port address (16 bits)
- Define the application program in the destination computer, e.g. Telnet = 23
- Sequence number (32 bits)
- Define the number assigned to the first byte of data contained in a segment
- Acknowledgement number (32 bits)
- Valid only if the ACK bit in the control field is set – in this case, it defines the byte sequence number that is next expected (in unit of bytes)
- To piggyback positive acknowledgment for the receipt of data from the other communication device
- ACK is “cumulative” – i.e. ACK n means all data before byte n have been received without error
- HLEN (Header Length) (4 bits)
- Length of TCP header (in unit of 4 bytes).
- Reserved (6 bits) - all 0s now, reserved for future use
- Control field (6 bits):
- URG - urgent
- ACK - the acknowledgment number is valid
- PSH - the segment should be read immediately
- RST - reset the connection now
- SYN - used in connection establishment
- FIN - used in connection termination
- Window size (16 bits)
- Defines the size of the sliding window by reciever side
- Maximum window size is 2^16 – 1
- Checksum (16 bits)
- Error detection
- Urgent pointer (16 bits)
- Valid only when the URG control bit is set
- Used when the segment contain urgent data
- The urgent data number are from (Sequence number) to (Sequence number + Urgent pointer)
- Options - The common use options are
- Maximum Segment Size
- specify the maximum segment size (usually to match with the receiver’s buffer size)
- Window Scale Factor
- Scale up the Window by 2^F where maximum allow F = 14
- Timestamp
- Used to calculate how long it takes to travel from the sender to the reciever.
- Maximum Segment Size
Connection Establishment
As TCP transmits data in full-duplex mode, each party must initialize communication and get approval from the other part before any data are transferred. That’s a 3-way handshaking.
- Connection request from Client
- Connection confirmation from Server
- Acknowledgment of confirmation from Client
The Sequence number only increase when the segment contains data.
Connection request,Connection confirmation and Acknowledgment of confirmation has no data.
However, Connection request and Connection confirmation will consume 1 Sequence number(measured in unit of byte).
- A SYN segment cannot carry data, but it consumes one sequence number
- A SYN + ACK segment cannot carry data, but does consume one sequence number.
The Acknowledgment of confirmation will not consume 1 sequence number.
- An ACK segment, if carrying no data, consumes no sequence number.
Therefore: Segment 1 and Segment 2 consume 1 Sequence number. Segment 3 will not consume any Sequence number.
Before the Client make the Request, the Server should become Ready first
- Server program tells its TCP that it is ready to accept a connection
- Called “passive open”
- Then Client program issues a request for an “active open”
This is same as previous notation but “passive open” is included.
- The Segment 3 can be 8000 or 8001, but the next segment must be 8001 because Segment 1 already consumed a sequence number.
Data Transfer using 3-Way Handshake
Connection Termination using 3-Way Handshake
- Terminate by seting FIN bit to 1
- The FIN segment consumes 1 sequence number.
- The FIN + ACK segment consumes 1 sequence number.
- An ACK segment, if carrying no data, consumes no sequence number.
Some special situation (Half-Close)
If the client has no data to send, It will try to close the connection.
But if at that time the server still have some data to send, the server will go into Half Close mode.
- Server send back a ACK to indicate it recieve the request, but Client is not yet ready to close.
- There will be no data sending from Client to server afterwards, until Server finished sending the remaining data segments (meanwhile Client will still send ACK to server)
- After Finish sending all the data from Server to Client, Server will send the Confirmation at that time by seting FIN and ACK bit to 1
- Client recieve the confirmation and then send the ACK. After Server recieve the ACK, Server closes its connection.
TCP Flow Control - Setting the Recieving Window Size
Flow Control is to Prevent from overwhelming the destination buffer.
- Use sliding window to make transmission more efficient as well as to control the flow of data
- The window size (rwnd) is depends on the available buffer size at the reciever.
- Avilable buffer size rwnd = Reciever Buffer Size – Buffered Data
Example
- 1- Client first send a SYN segement.
- Server set up its receieveing window rwnd.
- 2- Server then send back SYN + ACK to tell the size of rwnd. (That is 800 in the example)
- 3- Then Client will set the window.
- Sender can send at most 800 byte(according to recieving window of Server)
- 4- First segment only contain 200 byte is sent from Client to Server
- Available buffer size of Server become less (800 - 200 = 600)
- 5- Server send back ACK to tell a new rwnd value (i.e. current available buffer)
- Client after recieving the ACK, the window is slided to the right position by 200
- The sending window of client now become 600
- 6- Second segment contain 300 byte is sent from Client to Server
- Available buffer size of Server become less (600 - 300 = 300)
- At the same time, we assume 100 bytes are consumed, therefore buffer size = 300 + 100 = 400
- 7- Server send back ACK to tell a new rwnd value (i.e. current available buffer)
- Client after recieving the ACK, the window is slided to the right position by 200
- The sending window of client now become 400
- After some time, we assume another 200 bytes are consumed, therefore buffer size = 600
- Client after recieving the ACK, the window is slided to the left position by 200
- The sending window of client now become 600
- 8- Server send back ACK to tell a new rwnd value (i.e. current available buffer)
Note in practice, There are 1 sending window and 1 receieving window in each device.
TCP Error Control
TCP deliver the entire stream to the application program on the other end.
- In order
- Without error
- Without any part lost or duplicated
In other words, TCP can:
- Detect and resend corrupted segments
- Resend lost segments
- Storing out-of-order segments
- Detecting and discarding duplicated segments
TCP Error Control - Acknowledgements
TCP uses acknowledgments to confirm the receipt of data segments.
The Common Rules when to generate ACK
Rule 1: Piggybacking
When A sends a data segment to B, it must include (piggyback) an acknowledgment that gives the next sequence number it expects to receive.
Rule 2: Timeout
When the receiver has no data to send and it receives an in-order segment and the previous segment has already been acknowledged, the receiver delays sending an ACK segment until another segment arrives or until a period of time (~500ms) has passed.
Rule 3: You get annoyed
When a segment arrives with a sequence number that is expected by the receiver, and the previous in-order segment has not been acknowledged, the receiver immediately sends an ACK segment.
Rule 4: Dude it is out-of-order!
When a segment arrives with an out-of-order sequence number that is higher than expected, the receiver immediately sends an ACK segment announcing the sequence number of the next expected segment.
- Then, the sender retransmits the segment in the front of the queue after the Retransmission time-out.
Unlike the Go-back-N protocol discussed before, TCP implementation today stores out-of-order segments until the missing segments arrive.
Rule 5: Dad you finally finish buying the milk
When a missing segment arrives, the receiver sends an ACK segment to annount the next sequence number expected.
Rule 6:
If a duplicate segment arrives, the receiver discards the segment, immediately sends an acknowledgment indicating the next in-order segment expected.
- Normally duplicated segments is caused by lost ACK.
TCP Error Control - Retransmission
Normally we rely on timeout to trigger the retransmission.
- In order to have faster retransmission, TCP also developed rules for Retransmission rather than timeout.
- Whenever 3 duplicate ACK is received, it will trigger the retransmission
This implementation avoids the long delay of RTO
(called Fast Retransmission, one of the TCP congestion control mechanism)