CN Notes
CN Notes
CN Notes
1. INTRODUCTION
The transport layer is the fourth layer of the OSI model and is the core of the
Internet model.
It responds to service requests from the session layer and issues service
requests to the network Layer.
The transport layer provides transparent transfer of data between hosts.
It provides end-to-end control and information transfer with the quality of
service needed by the application program.
It is the first true end-to-end layer, implemented in all End Systems (ES).
1
21CS1403 – Computer Networks Unit 4
Process-to-Process Communication
The Transport Layer is responsible for delivering data to the appropriate
application process on the host computers.
This involves multiplexing of data from different application processes,
i.e. forming data packets, and adding source and destination port
numbers in the header of each Transport Layer data packet.
Together with the source and destination IP address, the port numbers
constitutes a network socket, i.e. an identification address of the
process-to-process communication.
Flow Control
Flow Control is the process of managing the rate of data
transmission between two nodes to prevent a fast sender from
overwhelming a slow receiver.
2
21CS1403 – Computer Networks Unit 4
Error Control
Error control at the transport layer is responsible for
1. Detecting and discarding corrupted packets.
2. Keeping track of lost and discarded packets and resending them.
3. Recognizing duplicate packets and discarding them.
4. Buffering out-of-order packets until the missing packets arrive.
Error Control involves Error Detection and Error Correction
Congestion Control
Congestion in a network may occur if the load on the network (the
number of packets sent to the network) is greater than the capacity of
the network (the number of packets a network can handle).
Congestion control refers to the mechanisms and techniques that
control the congestion and keep the load below the capacity.
Congestion Control refers to techniques and mechanisms that can either
prevent congestion, before it happens, or remove congestion, after it has
happened
Congestion control mechanisms are divided into two categories,
Open loop - prevent the congestion before it happens.
Closed loop - remove the congestion after it happens.
PORT NUMBERS
A transport-layer protocol usually has several responsibilities.
One is to create a process-to-process communication.
Processes are programs that run on hosts. It could be either server or client.
A process on the local host, called a client, needs services from a
process usually on the remote host, called a server.
Processes are assigned a unique 16-bit port number on that host.
3
21CS1403 – Computer Networks Unit 4
ICANN (Internet Corporation for Assigned Names and Numbers) has divided
the port numbers into three ranges:
Well-known ports
Registered
Ephemeral ports (Dynamic Ports)
WELL-KNOWN PORTS
These are permanent port numbers used by the servers.
They range between 0 to 1023.
This port number cannot be chosen randomly.
These port numbers are universal port numbers for servers.
Every client process knows the well-known port number of the
corresponding server process.
For example, while the client process can use an ephemeral (temporary)
port number, 52,000 to identify itself, the server process must use the
well-known (permanent) port number 13.
4
21CS1403 – Computer Networks Unit 4
REGISTERED PORTS
The ports ranging from 1024 to 49,151 are not assigned or controlled.
5
21CS1403 – Computer Networks Unit 4
UDP PORTS
Processes (server/client) are identified by an abstract locator known as port.
Server accepts message at well known port.
Some well-known UDP ports are 7–Echo, 53–DNS, 111–RPC, 161–SNMP, etc.
< port, host > pair is used as key for demultiplexing.
Ports are implemented as a message queue.
When a message arrives, UDP appends it to end of the queue.
When queue is full, the message is discarded.
When a message is read, it is removed from the queue.
When an application process wants to receive a message, one is removed
from the front of the queue.
If the queue is empty, the process blocks until a message becomes available.
6
21CS1403 – Computer Networks Unit 4
Checksum
UDP computes its checksum over the UDP header, the contents of the
message body, and something called the pseudoheader.
The pseudoheader consists of three fields from the IP header—protocol
number, source IP address, destination IP address plus the UDP length
field.
Data
Data field defines tha actual payload to be transmitted.
Its size is variable.
7
21CS1403 – Computer Networks Unit 4
UDP SERVICES
Process-to-Process Communication
UDP provides process-to-process communication using socket addresses,
a combination of IP addresses and port numbers.
Connectionless Services
UDP provides a connectionless service.
There is no connection establishment and no connection termination .
Each user datagram sent by UDP is an independent datagram.
There is no relationship between the different user datagrams even if they
are coming from the same source process and going to the same destination
program.
The user datagrams are not numbered.
Each user datagram can travel on a different path.
Flow Control
UDP is a very simple protocol.
There is no flow control, and hence no window mechanism.
The receiver may overflow with incoming messages.
The lack of flow control means that the process using UDP should
provide for this service, if needed.
Error Control
There is no error control mechanism in UDP except for the checksum.
This means that the sender does not know if a message has been lost or
duplicated.
When the receiver detects an error through the checksum, the user
datagram is silently discarded.
The lack of error control means that the process using UDP should provide
for this service, if needed.
Checksum
UDP checksum calculation includes three sections: a pseudoheader, the
UDP header, and the data coming from the application layer.
The pseudoheader is the part of the header in which the user datagram is
to be encapsulated with some fields filled with 0s.
8
21CS1403 – Computer Networks Unit 4
Figure shows the checksum calculation for a very small user datagram with only 7
bytes of data. Because the number of bytes of data is odd, padding is added for
checksum calculation. The pseudoheader as well as the padding will be dropped
when the user datagram is delivered to IP.
APPLICATIONS OF UDP
UDP is used for management processes such as SNMP.
UDP is used for route updating protocols such as RIP.
UDP is a suitable transport protocol for multicasting. Multicasting
9
21CS1403 – Computer Networks Unit 4
PROBLEM 1:
SOLVED PROBLEMS
Solution
(1) The source port number is the first four hexadecimal digits (CB84), which
means that the source port number is 52100.
(2) The destination port number is the second four hexadecimal digits (000D),
which means that the destination port number is 13.
(3) The third four hexadecimal digits (001C) define the length of the whole UDP
packet as 28 bytes.
(4) The length of the data is the length of the whole packet minus the length of
the header, or 28 − 8 = 20 bytes.
(5) Since the destination port number is 13 (well-known port), the packet is
from the client to the server.
(6) The client process is the Daytime.
PROBLEM 2 : (CHECKSUM)
What value is sent for the checksum in each one of the following hypothetical
situations?
(1) The sender decides not to include the checksum.
(2) The sender decides to include the checksum, but the value of the sum is all
1s.
(3) The sender decides to include the checksum, but the value of the sum is all
0s.
Solution
(1) The value sent for the checksum field is all 0s to show that the checksum
is not calculated.
(2) When the sender complements the sum, the result is all 0s; the sender
complements the result again before sending. The value sent for the
10
21CS1403 – Computer Networks Unit 4
(3) This situation never happens because it implies that the value of every term
included in the calculation of the sum is all 0s, which is impossible; some
fields in the pseudoheader have nonzero values.
TCP SERVICES
Process-to-Process Communication
TCP provides process-to-process communication using port numbers.
Stream Delivery Service
TCP is a stream-oriented protocol.
TCP allows the sending process to deliver data as a stream of bytes and
allows the receiving process to obtain data as a stream of bytes.
TCP creates an environment in which the two processes seem to be
connected by an imaginary “tube” that carries their bytes across the
Internet.
The sending process produces (writes to) the stream and the
receiving process consumes (reads from) it.
Full-Duplex Communication
TCP offers full-duplex service, where data can flow in both directions at the
same time.
11
21CS1403 – Computer Networks Unit 4
Each TCP endpoint then has its own sending and receiving buffer, and
segments move in both directions.
Connection-Oriented Service
TCP is a connection-oriented protocol.
Reliable Service
TCP is a reliable transport protocol.
It uses an acknowledgment mechanism to check the safe and sound arrival
of data.
TCP SEGMENT
A packet in TCP is called a segment.
Data unit exchanged between TCP peers are called segments.
A TCP segment encapsulates the data received from the application layer.
The TCP segment is encapsulated in an IP datagram, which in turn is
encapsulated in a frame at the data-link layer.
TCP is a byte-oriented protocol, which means that the sender writes bytes
into a TCP connection and the receiver reads bytes out of the TCP
connection.
12
21CS1403 – Computer Networks Unit 4
TCP does not, itself, transmit individual bytes over the Internet.
TCP on the source host buffers enough bytes from the sending process to
fill a reasonably sized packet and then sends this packet to its peer on the
destination host.
TCP on the destination host then empties the contents of the packet into a
receive buffer, and the receiving process reads from this buffer at its
leisure.
TCP connection supports byte streams flowing in both directions.
The packets exchanged between TCP peers are called segments, since each
one carries a segment of the byte stream.
TCP PACKET FORMAT
Each TCP segment contains the header plus the data.
The segment consists of a header of 20 to 60 bytes, followed by data
from the application program.
The header is 20 bytes if there are no options and up to 60 bytes if
it contains options.
Connection Establishment
While opening a TCP connection the two nodes(client and server) want to
agree on a set of parameters.
The parameters are the starting sequence numbers that is to be used
for their respective byte streams.
Connection establishment in TCP is a three-way handshaking.
1. Client sends a SYN segment to the server containing its initial sequence
number (Flags = SYN, SequenceNum = x)
2. Server responds with a segment that acknowledges client’s segment and
specifies its initial sequence number (Flags = SYN + ACK, ACK = x + 1
SequenceNum = y).
3. Finally, client responds with a segment that acknowledges server’s sequence
number (Flags = ACK, ACK = y + 1).
The reason that each side acknowledges a sequence number that is one
larger than the one sent is that the Acknowledgment field actually
identifies the “next sequence number expected,”
A timer is scheduled for each of the first two segments, and if the
expected response is not received, the segment is retransmitted.
14
21CS1403 – Computer Networks Unit 4
Data Transfer
After connection is established, bidirectional data transfer can take
place.
The client and server can send data and acknowledgments in both
directions.
Connection Termination
Connection termination or teardown can be done in two ways :
Three-way Close and Half-Close
15
21CS1403 – Computer Networks Unit 4
3. When SYN segment arrives at the server, it moves to SYN_RCVD state and
responds with a SYN + ACK segment.
4. Arrival of SYN + ACK segment causes the client to move to ESTABLISHED
state and sends an ACK to the server.
5. When ACK arrives, the server finally moves to ESTABLISHED state.
SOLVED EXAMPLE
Suppose a TCP connection is transferring a file of 5000 bytes. The first byte is
numbered 10001.What are the sequence numbers for each segment if data are
sent in five segments, each carrying 1000 bytes?
Solution
The following shows the sequence number for each segment:
Advertised Window
To achieve flow control, TCP uses the AdvertisedWindow field.
Receiver advertises its window size to the sender using AdvertisedWindow
field.
Sender thus cannot have unacknowledged data greater than
AdvertisedWindow.
Send Buffer
Sending TCP maintains send buffer which contains 3 segments
(1) acknowledged data
(2) unacknowledged data
(3) data to be transmitted.
Send buffer maintains three pointers
(1) LastByteAcked, (2) LastByteSent, and (3) LastByteWritten
such that:
LastByteAcked ≤ LastByteSent ≤ LastByteWritten
A byte can be sent only after being written and only a sent byte can be
acknowledged.
18
21CS1403 – Computer Networks Unit 4
Bytes to the left of LastByteAcked are not kept as it had been acknowledged.
Receive Buffer
Receiving TCP maintains receive buffer to hold data even if it arrives out-of-
order.
Receive buffer maintains three pointers namely
(1) LastByteRead, (2) NextByteExpected, and (3)
LastByteRcvd such that:
LastByteRead ≤ NextByteExpected ≤ LastByteRcvd + 1
A byte cannot be read until that byte and all preceding bytes have been
received.
If data is received in order, then NextByteExpected = LastByteRcvd + 1
Bytes to the left of LastByteRead are not buffered, since it is read by the
application.
0.
AdvertisedWindow field is designed to allow sender to keep the pipe
full.
TCP TRANSMISSION
TCP has two mechanism to trigger the transmission of a segment.
They are
o Silly Window Syndrome - Uses Maximum Segment Size (MSS)
o Nagle’s Algorithm - Uses Timeout
Silly Window Syndrome
When either the sending application program creates data slowly or the
receiving application program consumes data slowly, or both, problems
arise.
Any of these situations results in the sending of data in very small
segments, which reduces the efficiency of the operation.
This problem is called the silly window syndrome.
Nagle’s Algorithm
If there is data to send but is less than MSS, then we may want to wait some
amount of time before sending the available data
If we don’t wait long enough, it may end up sending small segments resulting
in Silly Window Syndrome.
The solution is to introduce a timer and to transmit when the timer expires
20
21CS1403 – Computer Networks Unit 4
21
21CS1403 – Computer Networks Unit 4
For example, when ACK arrives for 1 packet, 2 packets are sent. When ACK
for both packets arrive, 3 packets are sent and so on.
CongestionWindow increases and decreases throughout lifetime of the
connection.
Slow Start
Slow start is used to increase CongestionWindow exponentially from a cold
start.
Source TCP initializes CongestionWindow to one packet.
TCP doubles the number of packets sent every RTT on successful
transmission.
When ACK arrives for first packet TCP adds 1 packet to CongestionWindow
and sends two packets.
When two ACKs arrive, TCP increments CongestionWindow by 2 packets
and sends four packets and so on.
Instead of sending entire permissible packets at once (bursty traffic),
packets are sent in a phased manner, i.e., slow start.
22
21CS1403 – Computer Networks Unit 4
For example, packets 1 and 2 are received whereas packet 3 gets lost.
o Receiver sends a duplicate ACK for packet 2 when packet 4 arrives.
o Sender receives 3 duplicate ACKs after sending packet 6 retransmits
packet 3.
o When packet 3 is received, receiver sends cumulative ACK up to packet
6.
The congestion window trace will look like
TCP VERSIONS
Three versions of TCP EXISTS :
Taho TCP, Reno TCP & New Reno TCP.
24
21CS1403 – Computer Networks Unit 4
Taho TCP:
The early TCP is known as Taho TCP.
Taho TCP uses only two different algorithms in their congestion policy:
Slow start and Congestion avoidance.
Reno TCP
A newer version of TCP, called Reno TCP, added a new state to the
congestion- control FSM, called the fast-recovery state.
This version uses the two signals of congestion : time-out and three
duplicate ACKs, differently.
Normally TCP moves to the slow-start state
On the other hand, if three duplicate ACKs arrive, TCP moves to the fast-
recovery state and remains there as long as more duplicate ACKs arrive.
The fast-recovery state is a state somewhere between the slow-start
and the congestion-avoidance states.
NewReno TCP
The later version of TCP, is called NewReno TCP.
It makes an extra optimization on the Reno TCP.
In this version, TCP checks to see if more than one segment is lost in the
current window when three duplicate ACKs arrive.
25
21CS1403 – Computer Networks Unit 4
When TCP receives three duplicate ACKs, it retransmits the lost segment
until a new ACK arrives.
NewReno TCP retransmits this segment to avoid receiving more and more
duplicate ACKs for it.
26
21CS1403 – Computer Networks Unit 4
Using a queue length of 1 as the trigger for setting the congestion bit.
A router sets this bit in a packet if its average queue length is greater than
or equal to 1 at the time the packet arrives.
Computing average queue length at a router using DEC bit
Average queue length is measured over a time interval that includes the
Average Queue Length = last busy + last idle cycle + current busy cycle.
It calculates the average queue length by dividing the curve area with time
interval.
Each router is programmed to monitor its own queue length, and when it
detects that there is congestion, it notifies the source to adjust its congestion
window.
DECbit may lead to tail drop policy, whereas RED drops packet based on drop
probability in a random manner.
Drop each arriving packet with some drop probability whenever
the queue length exceeds some drop level. This idea is called early
random drop.
The queue length is measured every time a new packet arrives at the gateway.
RED has two queue length thresholds that trigger certain activity:
MinThreshold and MaxThreshold
28
21CS1403 – Computer Networks Unit 4
Multihoming
An SCTP association supports multihoming service.
The sending and receiving host can define multiple IP addresses in each end
for an association.
In this fault-tolerant approach, when one path fails, another interface can be
used for data delivery without interruption.
Full-Duplex Communication
SCTP offers full-duplex service, where 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.
Connection-Oriented Service
SCTP is a connection-oriented protocol.
In SCTP, a connection is called an association.
If a client wants to send and receive message from server , the steps are :
o Step1: The two SCTPs establish the connection with each other.
o Step2: Once the connection is established, the data gets
exchanged in both the directions.
o Step3: Finally, the association is terminated.
Reliable Service
SCTP is a reliable transport protocol.
It uses an acknowledgment mechanism to check the safe and sound arrival of
data.
SCTP Features
The following shows the general features of SCTP.
29
21CS1403 – Computer Networks Unit 4
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 SI is a 16-bit number
starting from 0.
Stream Sequence Number (SSN)
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).
An SCTP packet has a mandatory general header and a set of blocks called chunks.
General Header
The general header (packet header) defines the end points of each association
to which the packet belongs
It guarantees that the packet belongs to a particular association
It also preserves the integrity of the contents of the packet including the header
itself.
There are four fields in the general header:
o Source port
This field identifies the sending port.
Destination port
This field identifies the receiving port that hosts use to route the
packet to the appropriate endpoint/application.
Verification tag
A 32-bit random value created during initialization to distinguish stale
packets from a previous connection.
Checksum
The next field is a checksum. The size of the checksum is 32 bits.
SCTP uses CRC-32 Checksum.
Chunks
Control information or user data are carried in chunks.
Chunks have a common layout.
30
21CS1403 – Computer Networks Unit 4
The first three fields are common to all chunks; the information field
depends on the type of chunk.
The type field can define up to 256 types of chunks. Only a few have been
defined so far; the rest are reserved for future use.
The flag field defines special flags that a particular chunk may need.
The length field defines the total size of the chunk, in bytes, including the
type, flag, and length fields.
Types of Chunks
An SCTP association may send many packets, a packet may contain
several chunks, and chunks may belong to different streams.
SCTP defines two types of chunks - Control chunks and Data chunks.
A control chunk controls and maintains the association.
A data chunk carries user data.
SCTP ASSOCIATION
SCTP is a connection-oriented protocol.
A connection in SCTP is called an association to emphasize multihoming.
SCTP Associations consists of three phases:
o Association Establishment
o Data Transfer
o Association Termination
Association Establishment
Association establishment in SCTP requires a four-way handshake.
In this procedure, a client process wants to establish an association with a
31
21CS1403 – Computer Networks Unit 4
The client sends the first packet, which contains an INIT chunk.
The server sends the second packet, which contains an INIT ACK chunk.
The INIT ACK also sends a cookie that defines the state of the server at this
moment.
The client sends the third packet, which includes a COOKIE ECHO chunk.
This is a very simple chunk that echoes, without change, the cookie sent by
the server. SCTP allows the inclusion of data chunks in this packet.
The server sends the fourth packet, which includes the COOKIE ACK
chunk that acknowledges the receipt of the COOKIE ECHO chunk. SCTP
allows the inclusion of data chunks with this packet.
Data Transfer
The whole purpose of an association is to transfer data between two ends.
After the association is established, bidirectional data transfer can take
place.
The client and the server can both send data.
SCTP supports piggybacking.
Types of SCTP data Transfer :
1. Multihoming Data Transfer
Data transfer, by default, uses the primary address of the
destination.
If the primary is not available, one of the alternative addresses is
used.
This is called Multihoming Data Transfer.
32
21CS1403 – Computer Networks Unit 4
2. Multistream Delivery
SCTP can support multiple streams, which means that the sender
process can define different streams and a message can belong to
one of these streams.
Each stream is assigned a stream identifier (SI) which uniquely
defines that stream.
SCTP supports two types of data delivery in each stream: ordered
(default) and unordered.
Association Termination
In SCTP,either of the two parties involved in exchanging data (client or
server) can close the connection.
SCTP does not allow a “half closed” association. If one end closes the
association, the other end must stop sending new data.
If any data are left over in the queue of the recipient of the termination
request, they are sent and the association is closed.
Association termination uses three packets.
Sender Side
The sender has one buffer (queue) and three variables: curTSN, rwnd, and
inTransit.
We assume each chunk is 100 bytes long. The buffer holds the chunks
produced by the process that either have been sent or are ready to be sent.
The first variable, curTSN, refers to the next chunk to be sent.
All chunks in the queue with a TSN less than this value have been sent, but
not acknowledged; they are outstanding.
The second variable, rwnd, holds the last value advertised by the receiver (in
bytes).
The third variable, inTransit, holds the number of bytes in transit, bytes sent
33
21CS1403 – Computer Networks Unit 4
A chunk pointed to by curTSN can be sent if the size of the data is less
than or equal to the quantity rwnd - inTransit.
After sending the chunk, the value of curTSN is incremented by 1 and now
points to the next chunk to be sent.
The value of inTransit is incremented by the size of the data in the
transmitted chunk.
When a SACK is received, the chunks with a TSN less than or equal to the
cumulative TSN in the SACK are removed from the queue and discarded.
The sender does not have to worry about them anymore.
The value of inTransit is reduced by the total size of the discarded chunks.
The value of rwnd is updated with the value of the advertised window in the
SACK.
Receiver Side
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.
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.
When the process reads a chunk, it removes it from the queue and adds
the size of the removed chunk to winSize (recycling).
34
21CS1403 – Computer Networks Unit 4
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.
SCTP ERROR CONTROL
SCTP 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.
Sender Side
At the sender site, it needs two buffers (queues): a sending queue
and a retransmission queue.
Three variables were used - rwnd, inTransit, and curTSN as described in
the previous section.
The following figure shows a typical design.
35
21CS1403 – Computer Networks Unit 4
The following figure shows a typical design for the receiver site and the
state of the receiving queue at a particular point in time.
36