You are on page 1of 68

TRANSPORT LAYER PROTOCOL

UNIT-4
BY
PROF. PRITEE .H. RAUT
(MARKS-18)
4.1. INTRODUCTION
 The transport layer is the fourth layer in the open system interconnection (OSI) model, and is
responsible for end-to-end communication over a network.
 It provides logical communication between application processes running on different hosts
within a layered architecture of protocols and other network components.

 Protocols used in transport layer given below:-


1. UDP
2. TCP
3. SCTP
Features
User Datagram Protocol(UDP)

 UDP does have any acknowledgment mechanism.


 UDP is good protocol for data flowing in one direction.
 UDP is simple and suitable for query based communications.
 UDP is connectionless protocol.
 UDP does not provide congestion control mechanism.
 UDP does notprovide guarantee ordered delivery of data.
 UDP is stateless .that means the sender does not get the acknowledgement for the packet which
has been sent.
 UDP is suitable protocol for streaming applications such as VoIP, multimedia streaming.
UDP DATAGRAM HEADER FORMAT
 UDP header is 8-bytes fixed and simple header, while for TCP it may vary from 20 bytes to 60
bytes. First 8 Bytes contains all necessary header information and remaining part consist of data.
 UDP port number fields are each 16 bits long, therefore range for port numbers defined from 0 to
65535; port number 0 is reserved.
 Port numbers help to distinguish different user requests or process.
UDP Header

UDP header contains four main parameters:

 Source Port - This 16 bits information is used to identify the source port of the packet.

 Destination Port - This 16 bits information, is used identify application level service on destination machine.

 Length - Length field specifies the entire length of UDP packet (including header). It is 16-bits field and
minimum value is 8-byte, i.e. the size of UDP header itself.

 Checksum -which is used in error checking -- its use is required in IPv6 and optional in IPv4.
UDP application
Here are few applications where UDP is used to transmit data:

 Domain Name Services


 Simple Network Management Protocol
 Trivial File Transfer Protocol
 Routing Information Protocol
 Kerberos
 Gaming, voice and video
UDP Advantages:
1. UDP has minimum overheads.
2. UDP reduces interaction between sender and receiver.
3. It is suitable protocol for multicasting as UDP supports packet switching.
4. UDP protocol uses packets of smaller size.
5. User Datagram provides faster delivery of data as there is no acknowledgment mechanism in UDP.

UDP Disadvantages:

6. No compensation for lost packets


7. Packets can arrive out of order
8. UDP is a unreliable protocol.
9. UDP protocol does not provide congestion control service.
10. Flow control is also not provided by UDP protocol.
11. There is no acknowledgment mechanism in UDP.
4.4 UDP SERVICES(4M)

1. Process to process communication


2. Connectionless services.
3. Flow control
4. Error control.
5. Checksum.
6. Congestion control.
7. Encapsulation and decapsulation.
8. Queuing
9. Multiplexing and demultiplexing.
OF TRANSMISSION CONTROL PROTOCOL(TCP)

 TCP is connection oriented protocol. TCP established connection or session before sending
actual data.
 TCP provides flow control
 TCP provides Error control
 TCP provides congestion control
 TCP is reliable protocol. TCP ensures that the data reaches intended destination in the same
order it was sent.
 TCP provides error-checking and recovery mechanism.
 TCP provides end-to-end communication.
 TCP operates in Client/Server point-to-point mode.
 TCP provides full duplex server, i.e. it can perform roles of both receiver and sende
TCP SERVICES(4M)(S-22)
Following are some of the services offered by TCP to the processes at the application layer.:

1) Stream delivery service.


2) Sending and receiving buffers.
3) Bytes and segments.
4) Full duplex service.
5) Connection oriented service.
6) Reliable service.
7) Process to process communication.
Stream delivery services:
 TCP is a stream-oriented protocol as it allows the sender to send the data in the form of a stream
of bytes and also allows the receiver to accept the data in the form of a stream of bytes. TCP
creates an environment in which both the sender and receiver are connected by an imaginary tube
known as a virtual circuit. This virtual circuit carries the stream of bytes across the internet.
Sending and Receiving Buffers:
 Because the sending and the receiving processes may not write or read data at the same speed,
TCP needs buffers for storage.
 There are two buffers, the sending buffer and the receiving buffer, one for each direction and
these buffers are also necessary for flow and error control mechanisms used by TCP.
Segments

 At the transport layer, TCP groups a number of bytes together into a packet called
segment. TCP adds a header to each segment and delivers the segment to the IP
for transmission.
 The segment is encapsulated in IP datagram and transmitted. This entire operation
is transparent to the receiving process. The segments may be received out of
order, lost, or corrupted and resent. All these are handled by TCP with the
receiving process unaware of any activities.
Full duplex service.

 TCP offers full-duplex service, in which data can flow in both directions at the
same time. Each TCP then has a sending and receiving buffer, and segments move
in both directions.
 When a process at site A wants to send and receive data from another process at
site B, the following occurs:

1. The two TCPs establish a connection between them.


2. Data are exchanged in both directions.
3. The connection is terminated.
Reliability

 TCP is a reliable transport protocol. It uses an acknowledgment mechanism for checking


the safe and sound arrival of data.
 It uses features like byte number and sequence number and acknowledgement number
so as to ensure reliability.
Connection oriented service

Unlike UDP, TCP provides connection oriented service. It defines 3 different phases:

 Connection establishment
 Data transfer
 Connection termination
Process-to-Process Communication
 TCP provides process-to-process communication using port numbers. The
following table lists some well-known port numbers used by TCP.
FEATURES OF TCP(4m)

A. Connection-oriented
B. Flow Control
C. Error Control
D. Congestion Control
Connection-oriented
 It is a connection-oriented service that means the data exchange occurs only after
the connection establishment. When the data transfer is completed, then the
connection will get terminated.
Flow Control
 Flow control tells the sender how much data should be sent to the receiver so that it is not lost. This
mechanism makes the sender wait for an acknowledgment before sending the next data.
 This will avoid data overflow at the receiver.
 There are two ways to control the flow of data:
1. Stop and Wait Protocol
2. Sliding Window Protocol
Error Control

 Error Control in the data link layer is a process of detecting and retransmitting the data which has
been lost or corrupted during the transmission of data.
 Any reliable system must have a mechanism for detecting and correcting such errors.

Types of error

Single bit Error: When there is a change in only one bit of the sender's data then it is called a single bit error.
Example: If the sender sends 101(5) to the receiver but the receiver receives 100(4) then it is a single bit error.
101(sent bits) → 100(received bits)

Burst Error: When there is a change in two or more bits of the sender’s data then it is called a burst error.

Example: If the sender sends 1011(11) to the sender but the receiver receives 1000(8) then it is a burst error.
1011(sent bits) → 1000(received bits)
Congestion Control (sample-4m)
 A state occurring in network layer when the message traffic is so heavy that it slows down
network response time, congestion occurs.
 TCP controls congestion by means of Window mechanism. TCP sets a window size telling
the other end how much data segment to send.
 Effects of Congestion
1. As delay increases, performance decreases.
2. If delay increases, retransmission occurs, making situation worse

 TCP may use Congestion control algorithms :


1. Leaky Bucket Algorithm
2. Token bucket Algorithm
TCP Segment Header

TCP segment consists of data bytes to be sent and a header that is added to the data by TCP
 Source Port Address –
16 bit field that holds the port address of the application that is sending the data segment.

 Destination Port Address –


16 bit field that holds the port address of the application in the host that is receiving the data
segment.

 Sequence Number –
 Sequence number is a 32 bit field.
 TCP assigns a unique sequence number to each byte of data contained in the TCP segment.
 This field contains the sequence number of the first data byte.

 Acknowledgement Number –
 32 bit field that holds the acknowledgement number
 It contains sequence number of the data byte that receiver expects to receive next from the sender.
 It is always sequence number of the last received data byte incremented by 1.
Header Length-

 Header length is a 4 bit field.


 It contains the length of TCP header.
 It helps in knowing from where the actual data begins.

The length of TCP header always lies in the range-


[20 bytes , 60 bytes]
 Control flags –

These are 6 1-bit control bits that control connection establishment, connection termination, connection abortion,
flow control, mode of transfer etc.
 URG: When URG bit is set to 1,It indicates the receiver that certain amount of data within the current segment is urgent.
 ACK: Acknowledgement number is valid( used in case of cumulative acknowledgement)
 PSH: Request for push. PSH bit is used to push the entire buffer immediately to the receiving application.
 RST: Reset the connection
 SYN: Synchronize sequence numbers
 FIN: Terminate the connection

 Window size –
 This field tells the window size of the sending TCP in bytes.
 Window size is a 16 bit field.
 It contains the size of the receiving window of the sender.
 It advertises how much data (in bytes) the sender can receive without acknowledgement.
 Thus, window size is used for Flow Control.
 Checksum –

This field holds the checksum for error control. It is mandatory in TCP as opposed to UDP.
 Checksum is a 16 bit field used for error control.
 It verifies the integrity of data in the TCP payload.
 Sender adds CRC checksum to the checksum field before sending the data.
 Receiver rejects the data that fails the CRC check.

 Urgent pointer –

This field (valid only if the URG control flag is set) is used to point to data that is urgently required that needs to reach
the receiving process at the earliest. The value of this field is added to the sequence number to get the byte number of
the last urgent byte. Urgent pointer is a 16 bit field.
This field is considered valid and evaluated only if the URG bit is set to 1 .
Options-
• Options field is used for several purposes.
• The size of options field vary from 0 bytes to 40 bytes.

Padding-
• Addition of dummy data to fill up unused space in the transmission unit and make it conform to the standard
size is called as padding.
• Options field is used for padding.
State the use of 6 flags in TCP header.(winter-19) 2-M
There are 6, 1-bit control bits that control connection establishment,
termination, abortion, flow control etc..

URG: When URG bit is set to 1,It indicates the receiver that certain amount of data within the current segment
is urgent.

ACK: Acknowledgement number is valid( used in case of cumulative acknowledgement)

PSH: Request for push. PSH bit is used to push the entire buffer
immediately to the receiving application.

RST: Reset the connection

SYN: Synchronize sequence numbers

FIN: Terminate the connection


List two advantages of using UDP over TCP. (W-19)

Advantages of using UDP over TCP:


1) UDP is connection less and unreliable transport layer protocol.
i.e. It does not require to maintain a connection.
2) UDP is transaction oriented and suitable for simple query
response protocols.
3) UDP is faster since it does not require acknowledgment.
4) Useful when time sensitivity is more important
The dump of a UDP header in hexadecimal format is as follows:
BC 82000 D 002 B 001 D 4M (W-19)
Obtain the following from it:
(i) Source port number
(ii) Destination port number
(iii) Total length
(iv) Length of the data

ANS:-The UDP header has four parts, each of two bytes.


That means we get the following interpretation of the header.
i) Source port number = BC8216 = 48258
ii) Destination port number = 000D16= 13
iii) Total length = 002B16 = 43 bytes
iv) Since the header is 8 bytes the data length is 43 − 8 =35 bytes.
QUE:-Whathappens when 2 hosts simultaneously try to establish a connection
in TCP?(W-19)(6M)

If 2 host Simultaneously try to establish connection:

When two clients on the same machine connect to the same server, the OS on that machine will generate
distinct TCP port numbers for each connection. It is possible for a client to request a specific TCP port to
connect from using the bind() system call; however, if two clients request the same port, only the first request
will succeed.
TCP Three-Way Handshake Process(W-19) 4M
 Three-Way HandShake or a TCP 3-way handshake is a process which is used in a TCP/IP network to
make a connection between the server and client.
 It is a three-step process that requires both the client and server to exchange synchronization and
acknowledgment packets before the real data communication process starts.

 A connection typically goes through three phases:

1.Connection establishment.
2.Data transfer.
3.Connection termination.
TCP CONNECTION ESTABLISHMENT (W-19) 4M
To establish a connection, the three-way (or 3-step) handshake occurs:

 SYN:
 The active open is performed by the client sending a SYN to the server.
 The client sets the segment’s sequence number to a random value J.

 SYN-ACK:
 In response, the server replies with a SYN-ACK.
 The acknowledgment number is set to one more than the received sequence number (J + 1), and the
sequence number that the server chooses for the packet is another random number, (K).

 ACK:
 Finally, the client sends an ACK back to the server.
 The sequence number is set to the received acknowledgement value i.e. (J+1), and the
acknowledgement number is set to one more than the received sequence number i.e. (K+ 1).
CONNECTION ESTABLISHMENT DIAGRAM
 At this point, both the client and server have received an acknowledgment of the connection.
 The steps 1, 2 establish the connection parameter (sequence number) for one direction and it
is acknowledged.
 The steps 2, 3 establish the connection parameter (sequence number) for the other direction
and it is acknowledged. With these, a full-duplex communication is established.
TCP CONNECTION TERMINATION

Both sides of a connection can terminate a TCP connection, and even one-sided termination is also
possible. This is also known as a half-open connection, whereby the other side is still allowed to
transfer data even if one side has already disconnected.

The individual steps of two-way termination (initiated by the client for the sake of simplicity in this
example) can be summarized as follows:

1. The client sends a FIN segment to notify the server that it no longer wants to send data. It sends
its own sequence number M, just as it does when the connection is established.
2. The server acknowledges receipt of the package with an ACK segment that contains the sequence
number plus 1 i.e (M+1).
3. When the server has finished the data transfer, it also sends a FIN packet, to which it adds its
sequence number (N).
4. Now it is the client's turn to send an ACK packet including the sequence number plus 1 i.e (N+1),
which officially terminates the TCP connection for the server.
Note: The red line is for a client; the blue line is for a server
TCP STATE TRANSITION DIAGRAM (6M)W-19
TCP State Transition Diagram

 A TCP connection goes through a series of states during its lifetime. Figure shows the state transition
diagram.
 Each state transition is indicated by an arrow, and the associated label indicates associated events and
actions.
 Connection establishment begins in the CLOSED state and proceeds to the ESTABLISHED state.
 Connection termination goes from the ESTABLISHED state to the CLOSED state.
 The normal transitions for a client are indicated by thick solid lines, and the normal transitions for a server are
denoted by dashed lines.
 Thus when a client does an active open, it goes from the CLOSED state, to SYN_SENT, and then to
ESTABLISHED.
 The server carrying out a passive open goes from the CLOSED state, to LISTEN, SYN_RCVD, and then to
ESTABLISHED.
 The client normally initiates the termination of the connection by sending a FIN. The associated state goes
from the ESTABLISHED state, to FIN_WAIT_1 while it waits for an ACK, to FIN_WAIT_2 while it waits
for the other side's FIN, and then to TIME WAIT after it sends the final ACK. When the TIME_WAIT 2MSL
period expires, the connection is closed.
Stream Control Transmission Protocol (SCTP)

 Stream Control Transmission Protocol (SCTP) It is a connection- oriented protocol

 It is reliable transport layer protocol.


 SCTP has mixed features of TCP and UDP.
 SCTP maintains the message boundaries and detects the lost data, duplicate data
as well as out-of-order data.
 SCTP provides the Congestion control
 SCTP provides Flow control.
 SCTP is especially designed for internet applications.
Multiple Streams
 TCP is a stream-oriented protocol.
 Each connection between a TCP client and a TCP server involves one single stream. The problem with
this approach is that a loss at any point in the stream blocks the delivery of the rest of the data.
 This can be acceptable when we are transferring text; it is not when we are sending real-time data such
as audio or video.
 SCTP allows multi stream service in each connection, which is called association in SCTP terminology.
 If one of the streams is blocked, the other streams can still deliver their data.
Multihoming

 Multihoming is simply defined as having connection to the Internet through more than one Internet Service
Provider (ISP).
 A TCP connection has involves one source and one destination IP address. This means that even if the sender
and receiver is a multihomed (connected to more than one physical address with multiple IP addresses), only
one IP addresses per end can be utilized during the connection .
 An SCTP on the other hand supports multihoming service. Multihoming allows two endpoints to set up an
association with multiple IP addresses for each endpoint .Therefore, sending and receiver can define multiple
IP addresses. If one path fails, another interface can be used for data delivery without interpretation.

Note: SCTP association allows multiple IP addresses for each end.


Process-to-Process Communication

 Process-to-Process Communication: SCTP uses all well-known ports in the TCP


space.
Full-Duplex Communication

 Like TCP, SCTP offers full-duplex service, in which data can flow in both
directions at the same time. Each SCTP then has a sending and receiving buffer,
and packets are sent in both directions.
Features of SCTP
 Some important features of SCTP are as stated below:

Transmission Sequence Number

 The unit of data in TCP is a byte. Data transfer in TCP is controlled by numbering bytes by using a sequence number.
On the other hand, the unit of data in SCTP is a DATA chunk that may or may not have a one-to-one relationship with
the message coming from the process because of fragmentation.
Stream Identifier
 In TCP, there is only one stream in each connection. In SCTP, there may be several streams in each association. Each
stream in SCTP needs to be identified by using a stream identifier (SI). Each data chunk must carry the SI in its header
so that when it arrives at the destination, it can be properly placed in its stream. The 51 is a 16-bit number starting from
O.
Stream Sequence Number
 When a data chunk arrives at the destination SCTP, it is delivered to the appropriate stream and in the proper order. This
means that, in addition to an SI, SCTP defines each data chunk in each stream with a stream sequence number (SSN).
Packets

In TCP, a segment carries data and control information. Data is carried as a collection of bytes; control information is
defined by six control flags in the header. The design of SCTP is totally different: data is carried as data chunks; control
information is carried as control chunks.

Flow Control

Like TCP, SCTP implements flow control to avoid overwhelming the receiver.

Error Control

Like TCP, SCTP implements error control to provide reliability. TSN numbers and acknowledgement numbers are used for
error control.

Congestion Control

Like TCP, SCTP implements congestion control to determine how many data chunks can be injected into the network.
PACKET
FORMAT
PACKET FORMAT OF SCTP
PACKET FORMAT
 The Stream Control Transmission Protocol (SCTP) has a simpler basic packet structure than
TCP. Each consists of two basic sections:

 The common header, which occupies the first 12 bytes. In the adjacent diagram.
 The data chunks, These chunks can carries user information data or controlled information .
Common Header Fields

 Every SCTP packet contains the Common header as seen above. The header contains four
different fields and is set for every SCTP packet.

 Source port - This field gives the source port of the packet, which port it was sent from. The same
as for TCP and UDP source port.
 Destination port - This is the destination port of the packet, ie., the port that the packet is going
to. It is the same as for the TCP and UDP destination port.
 Verification Tag - The verification tag is used to verify that the packet comes from the correct
sender.
 Checksum - Uses the cyclic redundancy check (CRC32) algorithm to detect errors that might
have been introduced during data transmission.
Data Chunk Fields
Chunk type:-
Identifies the type of information contained in the Chunk data.
Chunk flags.
This is 8 bit field define special flags that a particular chunk may need.
Chunk length.
This size of the chunk in bytes including the Chunk type, Chunk flags, Chunk length, and Chunk data
fields.
if chunk not carries no information or data the Length field will be set to 4.
Chunk data.
the chunk carries user data.
Receiver Site
 The receiver has one buffer (queue) and three variables. The queue holds the
received data chunks that have not yet been read by the process.
 The first variable holds the last TSN received, cumTSN.
 The second variable holds the available buffer size; winsize.
 The third variable holds the last accumulative acknowledgment, lastACK. The
following figure shows the queue and variables at the receiver site.
Flow control at receiver site

1. When the site receives a data chunk, it stores it at the end of the buffer (queue) and
subtracts the size of the chunk from winSize. The TSN number of the chunk is stored
in the cumTSN variable.
2. When the process reads a chunk, it removes it from the queue and adds the size of
the removed chunk to winSize (recycling).

3. When the receiver decides to send a SACK, it checks the value of lastAck; if it is
less than cumTSN, it sends a SACK with a cumulative TSN number equal to the
cumTSN. It also includes the value of winSize as the advertised window size.
Sender Site:
 The sender has one buffer (queue) and three variables: curTSN, rwnd, and inTransit, as shown in the
following figure. We assume each chunk is 100 bytes long.
Flow control at sender site
1. The buffer carries the chunks generated by the process which have ready to be sent or have
been sent.
2. The first variable carries CurTSN which refers to the next chunk which is to be sent. The
second variable rwnd contains the last advertised value by the receiver in bytes.
3. The in transit i.e third variable holds number of bytes in transit, bytes which have been sent but
not acknowledged yet.
Error Control in SCTP
 SCTP, like TCP, is a reliable transport layer protocol. It uses a SACK chunk to report the state of
the receiver buffer to the sender. Each implementation uses a different set of entities and timers
for the receiver and sender sites.
Receiver Site
 The last acknowledgment sent was for data chunk 20. The available window size is
1000 bytes.
 Chunks 21 to 23 have been received in order.
 The first out-of-order block contains chunks 26 to 28. The second out-of-order block
contains chunks 31 to 34.
 A variable holds the value of cumTSN. An array of variables keeps track of the
beginning and the end of each block that is out of order. An array of variables holds
the duplicate chunks received. Note that there is no need for storing duplicate chunks
in the queue and they will be discarded.
Sender Site
 At the sender site, it needs two buffers (queues): a sending queue and a retransmission queue. We
also use the three variables rwnd, inTransit, and curTSN as described in the previous section. The
following figure shows a typical design.
1. The sending queue holds chunks 23 to 40. The chunks 23 to 36 have already been sent, but not acknowledged; they are
outstanding chunks.
2. The curTSN points to the next chunk to be sent (37). We assume that each chunk is 100 bytes, which means that 1400
bytes of data (chunks 23 to 36) is in transit. The sender at this moment has a retransmission queue. When a packet is
sent, a retransmission timer starts for that packet (all data chunks in that packet). Some implementations use one single
timer for the entire association, but we continue with our tradition of one timer for each packet for simplification.
3. When the retransmission timer for a packet expires, the chunks in that packet are moved to the retransmission queue to
be resent. These chunks are considered lost, rather than outstanding. The chunks in the retransmission queue have
priority.
SCTP Assosiation

 Similar to TCP,SCTP is a connection in SCTP.


 The three phases in the connection oriented SCTP association are as follows:
1. Association establishment
2. Data transfer
3. Association termination
SCTP association establishment
 The client sends an INIT signal to the server to initiate an association.
 On receipt of the INIT signal, the server sends an INIT-ACK response to the client. This INIT-ACK signal
contains a state cookie. This state cookie must contain a Message Authentication Code (MAC), along with a
time stamp corresponding to the creation of the cookie, the life span of the state cookie, and the information
necessary to establish the association. The MAC is computed by the server based on a secret key only known
to it.
 On receipt of this INIT-ACK signal, the client sends a COOKIE-ECHO response, which just echoes the
state cookie.
 After verifying the authenticity of the state cookie using the secret key, the server then allocates the resources
for the association, sends a COOKIE-ACK response acknowledging the COOKIE-ECHO signal, and moves
the association to ESTABLISHED state.
SCTP association establishment
SCTP association termination
 The client sends a SHUTDOWN signal to the server, which tells the server that
the client is ready to close the connection.
 The server responds by sending a SHUTDOWN-ACK acknowledgement.
 The client then sends a SHUTDOWN-COMPLETE signal back to the server.
Important Questions
1. State any four features of TCP.(2M)(S-22)
2. State Different Appliction Of UDP.(2m)(s-22)
3. List And Explain Services Provided By TCP.(4M)(S-22)
4. Drwa state transition digram of TCP.(6M)(S-22)
5. Differentiate between TCP,UDP AND SCTP on the basis of reliability , connection management, transmission of message,
flow control , security and data delivery.(6m)(s-22)
6. State the use of 6 flags in TCP header.(2m)(w-19)
7. List two advantages of using UDP over TCP. (W-19)
8. What happens when 2 hosts simultaneously try to establish a connection in TCP?(W-19)(6M)
9. Compare TCP and UDP (4m)(w-19).
10. Explain the TCP connection establishment using a three way handshaking mechanism.(4m)(w-19)
11. Explain TCP connection management with the help of TCP connection management finite state machine.(w-19)(6m)
12. Explain the concept of TCP congestion control mechanism. (sample)
13. Describe packet format of SCTP with neat dig. (sample)
14. Describe flow control under SCTP.(SAMPLE)(4m)
15. Explain Association establishment process in SCTP(SAMPLE)

You might also like