Mod5.Tcp & Udp
Mod5.Tcp & Udp
Transport Layer
• To achieve this goal, the transport layer makes use of the services provided by the
network layer.
• The hardware and/or software within the transport layer that does the work is
called the transport entity.
• The transport entity can be located in the operating system kernel, in a separate
user process, in a library package bound into network applications, or conceivably
on the network interface card
Services Provided to the Upper Layers
• The connection-oriented transport service is similar to the connection-oriented
network service in many ways.
• In both cases, connections have three phases: establishment, data transfer, and
release.
• Addressing and flow control are also similar in both layers.
• Furthermore, the connectionless transport service is also very similar to the
connectionless network service.
• But, the users have no real control over the network layer, so they cannot solve
the problem of poor service
• In essence, the existence of the transport layer makes it possible for the
transport service to be more reliable than the underlying network service.
The (logical) relationship of the network, transport, and
application layers
TPDU (Transport Protocol Data Unit)
• TPDU (Transport Protocol Data Unit) –term used for messages sent from
transport entity to transport entity.
• Thus, TPDUs (exchanged by the transport layer) are contained in packets
(exchanged by the network layer).
• In turn, packets are contained in frames (exchanged by the data link
layer).
• When a frame arrives, the data link layer processes the frame header and
passes the contents of the frame payload field up to the network entity.
• The network entity processes the packet header and passes the contents
of the packet payload up to the transport entity(TE).
Nesting of TPDUs, packets, and frames
Transport Service Primitives
• Transport Service Primitives allow transport users (application programs) to
access the transport service.
• A transport-layer protocol in the TCP suite needs both the IP address and the port
number, at each end, to make a connection.
• The combination of an IP address and a port number is called a socket address.
• The client socket address defines the client process uniquely and server socket
address defines the server process uniquely.
Transport layer protocols
• The Internet has two main protocols in the transport layer, a connectionless
21
UDP Format
Source port-This is the port number used by the process running on the source
host. It is 16 bits long, which means that the port number can range from 0 to
65,535.
Destination port-This is the port number used by the process running on the
destination host. It is also 16 bits long. If the destination host is the server (a
client sending a request), the port number, in most cases, is a well-known port
number.
UDP Format
• UDP length:
• It is a 16-bit field that defines the total length of the user datagram, header
plus data.
• We can deduce the length of a UDP datagram that is encapsulated in an IP
datagram.
• UDP checksum:
Port Numbers
Stream Delivery
■ Colored area:
□ Contain received bytes that can be consumed by the
receiving process
Segments
□ TCP groups a number of bytes together into a packet
called a segment
■ A TCP packet is called a segment
■ TCP adds a header to each segment
■ Then, the segments are encapsulated in an IP datagram
□ Note: terms
■ UDP Datagram, TCP Segment
■ IP Datagram
■ MAC Frame
Figure 12-6
TCP Segments
• Numbering System
• Flow Control
• Error Control
• Congestion Control
Features of TCP protocol
Numbering System
□ Although TCP use segments for transmission and reception
■ There is no field for a segment number in the segment header, i.e., TCP
header
□ TCP uses sequence number and acknowledgement number to keep
track of the segment being transmitted or received
■ Notably, these two fields refer to the byte number, not the
segment number
□ Byte Number-TCP numbers all data bytes that are transmitted in a
connection
□ The numbering does not necessarily start from 0
■ It starts randomly ie between 0 and 2^32 – 1 for the number of the first byte
■ Byte numbering is used for flow and error control
Features of TCP protocol
Sequence Number
□ The sequence number for each segment is the number of the first byte carried in
that segment
□ Eg.
•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 is
sent in five segments, each carrying 1000 bytes?
Solution
• The following list shows the sequence
number for each segment:
Segment 1 ➡ Sequence Number: 10,001 (range: 10,001 to 11,000)
Segment 2 ➡ Sequence Number: 11,001 (range: 11,001 to 12,000)
Segment 3 ➡ Sequence Number: 12,001 (range: 12,001 to 13,000)
Segment 4 ➡ Sequence Number: 13,001 (range: 13,001 to 14,000)
Segment 5 ➡ Sequence Number: 14,001 (range: 14,001 to 15,000)
Example
■ Also byte-oriented
Congestion Control
□ TCP takes into account congestion in the
network
52
TCP segment format
53
The TCP Segment Header
• Source Port, Destination Port : Identify local end points of the connections
• Sequence number: Specifies the sequence number of the segment
• The first byte number in this segment
• In connection establishment, each party randomly generate an initial sequence
number (ISN)
• Acknowledgement Number: Specifies the next byte expected.
• TCP header length: Tells how many 32-bit words are contained in TCP header
■ Value of this field is between 5 and 15
□ TCP header is between 20-60 bytes
• Next comes a 6-bit field that is not used.
• Now comes six 1-bit flags
54
The TCP Segment Header
• URG: It is set to 1 if URGENT pointer is in use, which indicates start of
urgent data.
• PSH: Push the data(indicate that the receiving device should deliver the data
to receiving application a soon as possible, rather than buffering it)
• RST: It is used to reset a connection that has become confused due to reject
an invalid segment or refuse an attempt to open a connection.
• Checksum - This 16-bit field contains the checksum. The calculation of the checksum for TCP follows
the same procedure as the one described for UDP.
• Urgent pointer - This 16-bit field, which is valid only if the urgent flag is set, is used when the segment
contains urgent data.
• It defines a value that must be added to the sequence number to obtain the number of the last
urgent byte in the data section of the segment.
• Options field -provides a way to add extra facilities not covered by the regular header. Size is 0-40 bytes
• Most important option is the one that allows each host to specify the maximum TCP payload it is
56
Comparison
57
58
TCP CONNECTIONS
• In TCP, connection-oriented transmission requires three phases:
1. Connection establishment
2. Data transfer
3. Connection termination.
TCP Connection Establishment
• TCP transmits data in full-duplex mode.
• When two TCPs in two machines are connected, they are able to send segments
to each other simultaneously.
• This implies that each party must initialize communication and get approval from
the other party before any data are transferred.
• The connection establishment in TCP is called threeway handshaking ,since it
requires 3 steps to complete the connection establishment process
• When a client wants to make a connection to a server
■ Server performs the passive open
□ Tell TCP that it is ready to accept a connection
■ Client performs the active open
□ Tell TCP that it needs to be connected to the server
Connection establishment
□ Active open
■ The side that sends the first SYN
□ Passive open
■ The side that receives this SYN and sends the next SYN
□ Simultaneous open
■ Both processes issue an active open
□ In this case, both TCPs transmit a SYN + ACK segment to each other,
and one single connection is established between them
Three-way handshaking
Three-way Handshaking
8001
10001
Pushing Data
□ In TCP, both sender and receiver have buffers
to hold data
■ In sender, application data to be sent is held
temporarily in the buffer
■ In receiver, receiving data is temporarily held
in the buffer
■ Thus, for applications, they may
encounter delayed transmission and
reception
Pushing Data (Cont.)
□ In some cases, delayed transmission and
reception may not be acceptable
□ TCP thus support PUSH operation
■ Sending TCP must create a segment and send the
data immediately
□ Must not wait for the window to be filled
■ Receiving TCP must deliver data to the application
immediately
□ Does not wait for more data to come
Urgent Data
□ TCP is a stream-oriented protocol
■ Data is presented as a stream of bytes
■ Two choices
□ FIN segment is only a control segment
■ Consume only one sequence number
□ FIN segment can include the last chunk of data sent by the
client
Three-Way Handshaking (Cont.)
2. The server TCP sends the FIN+ACK segment
■ ACK bit is set
□ Confirm the receipt of FIN segment
■ FIN bit is set
□ Announce the closing of the connection in the other direction
■ Two choices
□ FIN+ACK segment is only a control segment
■ Consume only one sequence number
□ FIN +ACK segment can include the last chunk of data sent by
the server
Three-Way Handshaking (Cont.)
□ Client TCP sends the last ACK segment
■ ACK bit is set
□ Confirm the receipt of the FIN+ACK segment for
the TCP server
Three-Way Handshaking
X+1
87
TCP Transmission Policy
1. In the above example, the receiver has 4096-byte buffer.
2. If the sender transmits a 2048-byte segment that is
correctly received, the receiver will acknowledge the
segment.
3. Now the receiver will advertise a window of 2048 as it has
only 2048 of buffer space, now.
4. Now the sender transmits another 2048 bytes which are
acknowledged, but the advertised window is’0’.
5. The sender must stop until the application process on the
receiving host has removed some data from the buffer, at
which time TCP can advertise a layer window.
88
Retransmission
□ When to retransmit a segment
■ When a retransmission timer expires
■ When the sender receives three duplicate ACK
.
Silly Window Syndrome Solutions
• Nagle's algorithm and Clark's solution
• Nagle’s Algorithm tries to solve the problem caused by the sender
delivering 1 data byte at a time.
□ Two categories
■ Open-loop congestion control
(prevention)
■ Closed-loop congestion control (removal)
Open-Loop Congestion Control
□ Prevent congestion before it happens
□ Possible policies
■ Retransmission policy
□ Retransmission policy and retransmission timer should be
designed to optimize efficiency
■ Acknowledgment policy
□ Does not ACK every packet it receives
□ Sending fewer acknowledgments means imposing less load
on the network
■ Discard policy
□ Router should adopt good discard policy
Closed-Loop Congestion Control
□ Try to alleviate congestion after it happens
□ Possible mechanisms
■ Back pressure
□ When a router is congested, it can inform the previous upstream router
to reduce it outgoing rate
□ The action can be recursive all the way to the router just prior to the
source
■ Choke Packet
□ A router sends a packet to the source to inform congestion
□ This packet is called chock packet, like ICMP’s source quench packet
■ Implicit signaling
□ Source can detect an implicit signal warning of congestion
■ For example, the delay in receiving an acknowledgment
■ Explicit signaling
□ Router can send an explicit signal to the sender or receiver of congestion
■ For example, set a bit in a packet
TCP congestion control.
• TCP uses a congestion window(cwnd) in the sender side to
do congestion avoidance
• The congestion window indicates the maximum amount of
data that can be sent out on a connection with out being
acknowledged.
• TCP detects congestion when it fails to receive an
acknowledgement with in the estimated time out.
• In such situation it decreases the congestion window to one
maximum segment size.
Congestion Control in TCP
• Congestion in TCP is handled by using these three phases:
1. Slow Start
2. Congestion Avoidance(Additive Increase )
3. Congestion Detection(Multiplicative Decrease)
Phase 2 & 3 combinedly known as AIMD technique Additive
Increase Multiplicative Decrease
Slow Start Phase : exponential increment
• At the beginning,
■ congestion window size = maximum segment size (MSS)
106
Slow Start Phase
Congestion Avoidance
• After cwnd exceeds the ssthresh size, the TCP Congestion control
mechanism enters the congestion avoidance phase
• In this phase sender increases the congestion window size linearly to
avoid the congestion.
• On receiving each acknowledgement, sender increments the
congestion window size by 1 and the technique is known as Additive
increase.
• This phase continues until the congestion window size becomes equal
to the receiver window size.
Packets in transit during additive increase
109
Packets in transit during additive increase
110
Congestion Detection Phase
• In this phase, the sender identifies the segment loss
• When sender detects the loss of segments, it reacts in different ways
depending on how the loss is detected
• Case-01: Detection On Time Out
• In this, the timer time-out expires even before receiving acknowledgment for
a segment.
• In this case sender sets the slow start threshold to half of the current
congestion window size.
• Each time a timeout occurs, the source sets CongestionWindow to half of its
previous value.
• This halving of the CongestionWindow for each timeout corresponds to the
“multiplicative decrease” part of AIMD(Additive Increase /Multiplicative
Decrease)
• Slow start phase is resumed
Congestion Detection Phase
• Case-02: Detection On Receiving 3 Duplicate Acknowledgements-