SlideShare a Scribd company logo
COMPUTER NETWORKS
Unit-4
UDP and TCP
Position of Transport Layer Protocols in
The TCP/IP Protocol Suite
Presentation Outline
• User Datagram Protocol
• UDP Characteristics
• UDP Datagram Format
• UDP Applications
• Transmission Control Protocol
• TCP Services
• TCP Segment Format
UDP: User Datagram Protocol
• In TCP/IP protocol suite, using IP to
transport datagram (similar to IP datagram).
• Allows an application to send datagram to
other application on the remote machine.
• Delivery and duplicate detection are not
guaranteed.
• Low overhead: faster than TCP.
UDP Characteristics
• End-to-End: an application sends/receives data to/from
another application.
• Connectionless: Application does not need to preestablish
communication before sending data; application does not
need to terminate communication when finished.
• Message-oriented: application sends/receives individual
messages (UDP datagram), not packets.
• Best-effort: same best-effort delivery semantics as IP. I.e.
message can be lost, duplicated, and corrupted.
• Arbitrary interaction: application communicates with
many or one other applications.
• Operating system independent: identifying application
does not depend on O/S.
Protocol Port Number
• UDP uses Port Number to identify an application as
an endpoint.
• UDP messages are delivered to the port specified in
the message by the sending application.
• In general, a port can be used for any datagram, as
long as the sender and the receiver agrees
• In practice, a collection of well-known ports are used
for special purposes such as telnet, ftp, and email. E.g.
port 7 for Echo application.
• Local operating system provides an interface for
processes to specify and access a port.
UDP Multiplexing & Demultiplexing
• Sender: multiplexing of UDP datagrams.
– UDP datagrams are received from multiple application programs.
– A single sequence of UDP datagrams is passed to IP layer.
• Receiver: demultiplexing of UDP datagrams.
– Single sequence of UDP datagrams received from IP layer.
– UDP datagram received is passed to appropriate application.
Encapsulation and Layering
• UDP message is encapsulated into an IP datagram.
• IP datagram in turn is encapsulated into a physical frame for
actually delivery.
User Datagram
UDP packets, called user datagrams, have a fixed-size
header of 8 bytes made of four fields, each of 2 bytes
(16 bits).
User Datagram Format
• The first two fields define the source and destination port
numbers.
• The third field defines the total length of the user datagram,
header plus data. The 16 bits can define a total length of 0 to
65,535 bytes. However, the total length needs to be less because
a UDP user datagram is stored in an IP datagram with the total
length of 65,535 bytes.
• The last field can carry the optional checksum.
User Datagram Packet Format
The following is the contents of a UDP header in hexadecimal format.
a. What is the source port number?
b. What is the destination port number?
c. What is the total length of the user datagram?
d. What is the length of the data?
e. Is the packet directed from a client to a server or vice
versa?
f. What is the client process?
Example(Self-Learning)
Solution
a. The source port number is the first four hexadecimal
digits (CB84)16 or 52100
b. The destination port number is the second four
hexadecimal digits (000D)16 or 13.
c. The third four hexadecimal digits (001C)16 define the
length of the whole UDP packet as 28 bytes.
d. The length of the data is the length of the whole packet
minus the length of the header, or 28 − 8 = 20 bytes.
e. Since the destination port number is 13 (well-known
port), the packet is from the client to the server.
f. The client process is the Daytime (see Table 3.1).
Pseudoheader for Checksum Calculation
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.
Example(Self-Learning)
Checksum Calculation of A Simple UDP User
Datagram
What value is sent for the checksum in one of the
following hypothetical situations?
a. The sender decides not to include the checksum.
b. The sender decides to include the checksum, but the
value of the sum is all 1s.
c. The sender decides to include the checksum, but the
value of the sum is all 0s.
Example(Self-Learning)
Solution
a. The value sent for the checksum field is all 0s to show
that the checksum is not calculated.
b. When the sender complements the sum, the result is all
0s; the sender complements the result again before
sending. The value sent for the checksum is all 1s. The
second complement operation is needed to avoid
confusion with the case in part a.
c. 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.
19
Why Would Anyone Use UDP?
• Finer control over what data is sent and when
– As soon as an application process writes into the socket
– … UDP will package the data and send the packet
• No delay for connection establishment
– UDP just blasts away without any formal preliminaries
– … which avoids introducing any unnecessary delays
• No connection state
– No allocation of buffers, parameters, sequence #s, etc.
– … making it easier to handle many active clients at once
• Small packet header overhead
– UDP header is only eight-bytes long
20
Popular Applications That Use UDP
• Multimedia streaming
– Retransmitting lost/corrupted packets is not worthwhile
– By the time the packet is retransmitted, it’s too late
– E.g., telephone calls, video conferencing, gaming
• Simple query protocols like Domain Name System
– Overhead of connection establishment is overkill
– Easier to have application retransmit if needed
“Address for www.cnn.com?”
“12.3.4.15”
TCP
Transmission Control Protocol (TCP) is a connection-oriented,
reliable protocol.
TCP explicitly defines connection establishment, data transfer, and
connection teardown phases to provide a connection-oriented
service.
TCP Services
Before discussing TCP in detail, let us explain the
services offered by TCP to the processes at the
application layer.
Sending
process
Receiving
process
Stream of bytes
Stream Delivery
In UDP, a process sends messages to UDP for delivery. UDP
adds its own header to each of these messages and delivers it
to IP. Each message from the process is called a user
datagram, and becomes, eventually, one IP datagram. Neither
IP nor UDP recognizes any relationship between the
datagrams.
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 (seem to be connected by an imaginary
“tube” that carries their bytes across the Internet).
Stream Delivery
Stream of bytes
Sending
process
Receiving
process
Sending and Receiving Buffers
TCP uses buffers for storage, flow- and error-control.
One way to implement a buffer is to use a circular array of 1-byte locations.
Normally the buffers are hundreds or thousands of bytes, but for simplicity, we have
shown two buffers of 20 bytes each.
At the sender, the buffer has three types of chambers:
1. The white section: contains empty chambers that can be filled by the sending
process.
2. The colored (blue): area holds bytes that have been sent but not yet
acknowledged. The TCP sender keeps these bytes in the buffer until it receives
an acknowledgment.
3. The shaded area (yellow): contains bytes to be sent by the sending TCP.
Buffer at the receiver is divided into two areas:
4. The white area: contains empty chambers to be filled by bytes received from the
network.
5. The colored sections: contain received bytes that can be read by the receiving
process. When they are read, the chamber is recycled and added to the pool of
empty chambers.
Sending and Receiving Buffers
TCP groups a number of bytes together into a packet called a
segment.
TCP adds a header to each segment and delivers the segment to
the network layer for transmission.
TCP Segments
TCP Features
To provide the services mentioned in the
previous section, TCP has several features
that are briefly summarized in this section
and discussed later in detail.
Numbering System
Byte Number
When TCP receives bytes of data from a process, TCP stores
them in the sending buffer and numbers them (chooses an
arbitrary number between 0 and 232
− 1 for the number of the first
byte).
Sequence Number
TCP assigns a sequence number to each segment that is being
sent:
1. The sequence number of the first segment is the ISN (initial
sequence number), which is a random number.
2. The sequence number of any other segment is the sequence
number of the previous segment plus the number of bytes carried
by the previous segment.
Numbering System
Acknowledgment Number
the acknowledgment number defines the number of the next byte
that the party expects to receive.
The acknowledgment number is cumulative: which means that
the party takes the number of the last byte that it has received,
adds 1 to it, and announces this sum as the acknowledgment
number. For example, if a party uses 5643 as an acknowledgment
number, it has received all bytes from the beginning up to 5642.
Sequence Number Wrap Around
Bandwidth Time Until Wrap Around
T1 (1.5 Mbps) 6.4 hours
Ethernet (10 Mbps) 57 minutes
T3 (45 Mbps) 13 minutes
FDDI (100 Mbps) 6 minutes
STS-3 (155 Mbps) 4 minutes
STS-12 (622 Mbps) 55 seconds
STS-24 (1.2 Gbps) 28 seconds
• Protect against this by adding a 32-bit timestamp to TCP header
Segment
Before discussing TCP in more detail, let us discuss
the TCP packets themselves. A packet in TCP is
called a segment.
TCP Format
IP header TCP header TCP data
Sequence number (32 bits)
DATA
20 bytes 20 bytes
0 15 16 31
Source Port Number Destination Port Number
Acknowledgement number (32 bits)
window size
header
length
0 Flags
Options (if any)
TCP checksum urgent pointer
20
bytes
TCP segments have a 20 byte header with >= 0 bytes of data.
TCP Segment Format
TCP Header Fields
• Port Number:
– A port number identifies the endpoint of a connection.
– A pair <IP address, port number> identifies one endpoint of
a connection.
– Two pairs <client IP address, Client port number> and
<server IP address, server port number> identify a TCP
connection.
TCP
IP
Applications
23 104
80
Ports:
TCP
IP
Applications
7 16
80 Ports:
TCP Header Fields
• Sequence Number (SeqNo):
– Sequence number is 32 bits long.
– So the range of SeqNo is
0 <= SeqNo <= 232
-1  4.3 Gbyte
– Each sequence number identifies a byte in the byte
stream
– Initial Sequence Number (ISN) of a connection is set
during connection establishment
Q: What are possible requirements for ISN ?
TCP Header Fields
• Acknowledgement Number (AckNo):
– Acknowledgements are piggybacked, I.e
a segment from A -> B can contain an acknowledgement for a
data sent in the B -> A direction
Q: Why is piggybacking good ?
– A hosts uses the AckNo field to send
acknowledgements. (If a host sends an AckNo in a segment it
sets the “ACK flag”)
– The AckNo contains the next SeqNo that a hosts wants
to receive
Example: The acknowledgement for a segment withsequence
numbers 0-1500 is AckNo=1501
TCP header fields
• Acknowledge Number (cont’d)
– TCP uses the sliding window flow protocol to regulate
the flow of traffic from sender to receiver
– TCP uses the following variation of sliding window:
– no NACKs (Negative ACKnowledgement)
– only cumulative ACKs
• Example:
Assume: Sender sends two segments with “1..1500” and
“1501..3000”, but receiver only gets the second segment.
In this case, the receiver cannot acknowledge the second packet. It
can only send AckNo=1501, after receiving 1st
segment
TCP Header Fields
• Header Length (4bits):
– Length of header in 32-bit words
– Note that TCP header has variable length (with
minimum 20 bytes)
TCP Header Fields
• Flag bits:
– URG: Urgent pointer is valid
– If the bit is set, the following bytes contain an urgent
message in the range:
SeqNo <= urgent message <= SeqNo+urgent pointer
– ACK: Acknowledgement Number is valid
– PSH: PUSH Flag
– Notification from sender to the receiver that the receiver
should pass all data that it has to the application.
– Normally set by sender when the sender’s buffer is empty
TCP Header Fields
• Flag bits:
– RST: Reset the connection
– The flag causes the receiver to reset the connection
– Receiver of a RST terminates the connection and indicates
higher layer application about the reset
– SYN: Synchronize sequence numbers
– Sent in the first packet when initiating a connection
– FIN: Sender is finished with sending
– Used for closing a connection
– Both sides of a connection must send a FIN
TCP Header Fields
• Window Size:
– Each side of the connection advertises the window size
– Window size is the maximum number of bytes that a
receiver can accept.
– Maximum window size is 216
-1= 65535 bytes
• TCP Checksum:
– TCP checksum covers over both TCP header and TCP
data (also covers some parts of the IP header)
• Urgent Pointer:
– Only valid if URG flag is set
TCP Header Fields
• Options:
End of
Options kind=0
1 byte
NOP
(no operation) kind=1
1 byte
Maximum
Segment Size
kind=2
1 byte
len=4
1 byte
maximum
segment size
2 bytes
Window Scale
Factor
kind=3
1 byte
len=3
1 byte
shift count
1 byte
Timestamp kind=8
1 byte
len=10
1 byte
timestamp value
4 bytes
timestamp echo reply
4 bytes
TCP Header Fields
• Options:
– NOP is used to pad TCP header to multiples of 4 bytes
– Maximum Segment Size
– Window Scale Options
» Increases the TCP window from 16 to 32 bits, I.e., the
window size is interpreted differently
Q: What is the different interpretation ?
» This option can only be used in the SYN segment
(first segment) during connection establishment time
– Timestamp Option
» Can be used for roundtrip measurements
Pseudoheader Added To The TCP Datagram
Window size: This field defines the window size of the sending
TCP in bytes.
Checksum: The calculation of the checksum for TCP follows the
same procedure as UDP. Using checksum in the UDP datagram is
optional, but in TCP it’s mandatory. The same pseudoheader,
serving the same purpose, is added to the segment. For the TCP
pseudoheader, the value for the protocol field is 6.
Urgent pointer. This 16-bit field, which is valid only if the urgent
flag is set, is
used when the segment contains urgent data.
Options. There can be up to 40 bytes of optional information in
the TCP header.
Pseudoheader Added To The TCP Datagram
Frame
header
IP
header
Encapsulation
Application-layer data
TCP
header
Data-link layer payload
IP payload
TCP payload
TCP Vs UDP
Further Inquiries
Thank You

More Related Content

PPTX
Computer networks transport layer
PDF
Transport layer services
DOCX
UDP and TCP Protocol & Encrytion and its algorithm
PPTX
Transport layer protocol
PPTX
Unit 6 NAHI aa rha hai na ki koi baat nhi hai
PPT
unit 3 ns.ppt
PDF
Transport layer udp and tcp network
PDF
TCP/IP & UDP
Computer networks transport layer
Transport layer services
UDP and TCP Protocol & Encrytion and its algorithm
Transport layer protocol
Unit 6 NAHI aa rha hai na ki koi baat nhi hai
unit 3 ns.ppt
Transport layer udp and tcp network
TCP/IP & UDP

Similar to 2-CN_UDP_TCP_f7a922763a77c5ea2bc334f8e36c71f8.ppt (20)

PPT
UDP and TCP header.ppt
PPTX
Transport layer
PDF
Transmission control protocol tcp tcp tcp tcp
PPTX
TCP & UDP ( Transmission Control Protocol and User Datagram Protocol)
PPTX
07 coms 525 tcpip - udp
PPT
Unityfyfyufhufhhcfhfufhufhhufufhyrruruuf4-2.ppt
PPT
W14-15L28-29 Process to Process Communication.ppt
PPT
Mobile computing unit-5
PPTX
TCP and UDP comparison and itsi application.pptx
PPTX
User Datagram Protocol
PPTX
Transport layer protocols : TCP and UDP
PDF
UNit-4 Transport Layer and its protocols.pdf
PDF
Computer Communication Networks- TRANSPORT LAYER PROTOCOLS
PPT
Unit_3_TCP_UDP.ppt
PPTX
07 coms 525 tcpip - udp [autosaved]
PPT
transport layer protocols
PPT
LECTURE-Transport-Layer_lec.ppt
PDF
Lecture set 7
PPTX
Transport layer.pptx
PDF
DCN 5th ed. slides ch24 Transport-Layer Protocols.pdf
UDP and TCP header.ppt
Transport layer
Transmission control protocol tcp tcp tcp tcp
TCP & UDP ( Transmission Control Protocol and User Datagram Protocol)
07 coms 525 tcpip - udp
Unityfyfyufhufhhcfhfufhufhhufufhyrruruuf4-2.ppt
W14-15L28-29 Process to Process Communication.ppt
Mobile computing unit-5
TCP and UDP comparison and itsi application.pptx
User Datagram Protocol
Transport layer protocols : TCP and UDP
UNit-4 Transport Layer and its protocols.pdf
Computer Communication Networks- TRANSPORT LAYER PROTOCOLS
Unit_3_TCP_UDP.ppt
07 coms 525 tcpip - udp [autosaved]
transport layer protocols
LECTURE-Transport-Layer_lec.ppt
Lecture set 7
Transport layer.pptx
DCN 5th ed. slides ch24 Transport-Layer Protocols.pdf
Ad

Recently uploaded (20)

PPT
Quality review (1)_presentation of this 21
PPTX
Business Ppt On Nestle.pptx huunnnhhgfvu
PDF
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
PPTX
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PPT
ISS -ESG Data flows What is ESG and HowHow
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
PPTX
Computer network topology notes for revision
PPTX
climate analysis of Dhaka ,Banglades.pptx
PDF
Business Analytics and business intelligence.pdf
PDF
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
PPTX
Qualitative Qantitative and Mixed Methods.pptx
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PPTX
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
PPTX
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
PPTX
STUDY DESIGN details- Lt Col Maksud (21).pptx
PDF
Lecture1 pattern recognition............
Quality review (1)_presentation of this 21
Business Ppt On Nestle.pptx huunnnhhgfvu
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
ISS -ESG Data flows What is ESG and HowHow
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
Computer network topology notes for revision
climate analysis of Dhaka ,Banglades.pptx
Business Analytics and business intelligence.pdf
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
Qualitative Qantitative and Mixed Methods.pptx
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
Galatica Smart Energy Infrastructure Startup Pitch Deck
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
oil_refinery_comprehensive_20250804084928 (1).pptx
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
STUDY DESIGN details- Lt Col Maksud (21).pptx
Lecture1 pattern recognition............
Ad

2-CN_UDP_TCP_f7a922763a77c5ea2bc334f8e36c71f8.ppt

  • 2. Position of Transport Layer Protocols in The TCP/IP Protocol Suite
  • 3. Presentation Outline • User Datagram Protocol • UDP Characteristics • UDP Datagram Format • UDP Applications • Transmission Control Protocol • TCP Services • TCP Segment Format
  • 4. UDP: User Datagram Protocol • In TCP/IP protocol suite, using IP to transport datagram (similar to IP datagram). • Allows an application to send datagram to other application on the remote machine. • Delivery and duplicate detection are not guaranteed. • Low overhead: faster than TCP.
  • 5. UDP Characteristics • End-to-End: an application sends/receives data to/from another application. • Connectionless: Application does not need to preestablish communication before sending data; application does not need to terminate communication when finished. • Message-oriented: application sends/receives individual messages (UDP datagram), not packets. • Best-effort: same best-effort delivery semantics as IP. I.e. message can be lost, duplicated, and corrupted. • Arbitrary interaction: application communicates with many or one other applications. • Operating system independent: identifying application does not depend on O/S.
  • 6. Protocol Port Number • UDP uses Port Number to identify an application as an endpoint. • UDP messages are delivered to the port specified in the message by the sending application. • In general, a port can be used for any datagram, as long as the sender and the receiver agrees • In practice, a collection of well-known ports are used for special purposes such as telnet, ftp, and email. E.g. port 7 for Echo application. • Local operating system provides an interface for processes to specify and access a port.
  • 7. UDP Multiplexing & Demultiplexing • Sender: multiplexing of UDP datagrams. – UDP datagrams are received from multiple application programs. – A single sequence of UDP datagrams is passed to IP layer. • Receiver: demultiplexing of UDP datagrams. – Single sequence of UDP datagrams received from IP layer. – UDP datagram received is passed to appropriate application.
  • 8. Encapsulation and Layering • UDP message is encapsulated into an IP datagram. • IP datagram in turn is encapsulated into a physical frame for actually delivery.
  • 9. User Datagram UDP packets, called user datagrams, have a fixed-size header of 8 bytes made of four fields, each of 2 bytes (16 bits).
  • 11. • The first two fields define the source and destination port numbers. • The third field defines the total length of the user datagram, header plus data. The 16 bits can define a total length of 0 to 65,535 bytes. However, the total length needs to be less because a UDP user datagram is stored in an IP datagram with the total length of 65,535 bytes. • The last field can carry the optional checksum. User Datagram Packet Format
  • 12. The following is the contents of a UDP header in hexadecimal format. a. What is the source port number? b. What is the destination port number? c. What is the total length of the user datagram? d. What is the length of the data? e. Is the packet directed from a client to a server or vice versa? f. What is the client process? Example(Self-Learning)
  • 13. Solution a. The source port number is the first four hexadecimal digits (CB84)16 or 52100 b. The destination port number is the second four hexadecimal digits (000D)16 or 13. c. The third four hexadecimal digits (001C)16 define the length of the whole UDP packet as 28 bytes. d. The length of the data is the length of the whole packet minus the length of the header, or 28 − 8 = 20 bytes. e. Since the destination port number is 13 (well-known port), the packet is from the client to the server. f. The client process is the Daytime (see Table 3.1).
  • 15. 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. Example(Self-Learning)
  • 16. Checksum Calculation of A Simple UDP User Datagram
  • 17. What value is sent for the checksum in one of the following hypothetical situations? a. The sender decides not to include the checksum. b. The sender decides to include the checksum, but the value of the sum is all 1s. c. The sender decides to include the checksum, but the value of the sum is all 0s. Example(Self-Learning)
  • 18. Solution a. The value sent for the checksum field is all 0s to show that the checksum is not calculated. b. When the sender complements the sum, the result is all 0s; the sender complements the result again before sending. The value sent for the checksum is all 1s. The second complement operation is needed to avoid confusion with the case in part a. c. 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.
  • 19. 19 Why Would Anyone Use UDP? • Finer control over what data is sent and when – As soon as an application process writes into the socket – … UDP will package the data and send the packet • No delay for connection establishment – UDP just blasts away without any formal preliminaries – … which avoids introducing any unnecessary delays • No connection state – No allocation of buffers, parameters, sequence #s, etc. – … making it easier to handle many active clients at once • Small packet header overhead – UDP header is only eight-bytes long
  • 20. 20 Popular Applications That Use UDP • Multimedia streaming – Retransmitting lost/corrupted packets is not worthwhile – By the time the packet is retransmitted, it’s too late – E.g., telephone calls, video conferencing, gaming • Simple query protocols like Domain Name System – Overhead of connection establishment is overkill – Easier to have application retransmit if needed “Address for www.cnn.com?” “12.3.4.15”
  • 21. TCP Transmission Control Protocol (TCP) is a connection-oriented, reliable protocol. TCP explicitly defines connection establishment, data transfer, and connection teardown phases to provide a connection-oriented service.
  • 22. TCP Services Before discussing TCP in detail, let us explain the services offered by TCP to the processes at the application layer.
  • 24. In UDP, a process sends messages to UDP for delivery. UDP adds its own header to each of these messages and delivers it to IP. Each message from the process is called a user datagram, and becomes, eventually, one IP datagram. Neither IP nor UDP recognizes any relationship between the datagrams. 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 (seem to be connected by an imaginary “tube” that carries their bytes across the Internet). Stream Delivery
  • 26. TCP uses buffers for storage, flow- and error-control. One way to implement a buffer is to use a circular array of 1-byte locations. Normally the buffers are hundreds or thousands of bytes, but for simplicity, we have shown two buffers of 20 bytes each. At the sender, the buffer has three types of chambers: 1. The white section: contains empty chambers that can be filled by the sending process. 2. The colored (blue): area holds bytes that have been sent but not yet acknowledged. The TCP sender keeps these bytes in the buffer until it receives an acknowledgment. 3. The shaded area (yellow): contains bytes to be sent by the sending TCP. Buffer at the receiver is divided into two areas: 4. The white area: contains empty chambers to be filled by bytes received from the network. 5. The colored sections: contain received bytes that can be read by the receiving process. When they are read, the chamber is recycled and added to the pool of empty chambers. Sending and Receiving Buffers
  • 27. TCP groups a number of bytes together into a packet called a segment. TCP adds a header to each segment and delivers the segment to the network layer for transmission. TCP Segments
  • 28. TCP Features To provide the services mentioned in the previous section, TCP has several features that are briefly summarized in this section and discussed later in detail.
  • 29. Numbering System Byte Number When TCP receives bytes of data from a process, TCP stores them in the sending buffer and numbers them (chooses an arbitrary number between 0 and 232 − 1 for the number of the first byte). Sequence Number TCP assigns a sequence number to each segment that is being sent: 1. The sequence number of the first segment is the ISN (initial sequence number), which is a random number. 2. The sequence number of any other segment is the sequence number of the previous segment plus the number of bytes carried by the previous segment.
  • 30. Numbering System Acknowledgment Number the acknowledgment number defines the number of the next byte that the party expects to receive. The acknowledgment number is cumulative: which means that the party takes the number of the last byte that it has received, adds 1 to it, and announces this sum as the acknowledgment number. For example, if a party uses 5643 as an acknowledgment number, it has received all bytes from the beginning up to 5642.
  • 31. Sequence Number Wrap Around Bandwidth Time Until Wrap Around T1 (1.5 Mbps) 6.4 hours Ethernet (10 Mbps) 57 minutes T3 (45 Mbps) 13 minutes FDDI (100 Mbps) 6 minutes STS-3 (155 Mbps) 4 minutes STS-12 (622 Mbps) 55 seconds STS-24 (1.2 Gbps) 28 seconds • Protect against this by adding a 32-bit timestamp to TCP header
  • 32. Segment Before discussing TCP in more detail, let us discuss the TCP packets themselves. A packet in TCP is called a segment.
  • 33. TCP Format IP header TCP header TCP data Sequence number (32 bits) DATA 20 bytes 20 bytes 0 15 16 31 Source Port Number Destination Port Number Acknowledgement number (32 bits) window size header length 0 Flags Options (if any) TCP checksum urgent pointer 20 bytes TCP segments have a 20 byte header with >= 0 bytes of data.
  • 35. TCP Header Fields • Port Number: – A port number identifies the endpoint of a connection. – A pair <IP address, port number> identifies one endpoint of a connection. – Two pairs <client IP address, Client port number> and <server IP address, server port number> identify a TCP connection. TCP IP Applications 23 104 80 Ports: TCP IP Applications 7 16 80 Ports:
  • 36. TCP Header Fields • Sequence Number (SeqNo): – Sequence number is 32 bits long. – So the range of SeqNo is 0 <= SeqNo <= 232 -1  4.3 Gbyte – Each sequence number identifies a byte in the byte stream – Initial Sequence Number (ISN) of a connection is set during connection establishment Q: What are possible requirements for ISN ?
  • 37. TCP Header Fields • Acknowledgement Number (AckNo): – Acknowledgements are piggybacked, I.e a segment from A -> B can contain an acknowledgement for a data sent in the B -> A direction Q: Why is piggybacking good ? – A hosts uses the AckNo field to send acknowledgements. (If a host sends an AckNo in a segment it sets the “ACK flag”) – The AckNo contains the next SeqNo that a hosts wants to receive Example: The acknowledgement for a segment withsequence numbers 0-1500 is AckNo=1501
  • 38. TCP header fields • Acknowledge Number (cont’d) – TCP uses the sliding window flow protocol to regulate the flow of traffic from sender to receiver – TCP uses the following variation of sliding window: – no NACKs (Negative ACKnowledgement) – only cumulative ACKs • Example: Assume: Sender sends two segments with “1..1500” and “1501..3000”, but receiver only gets the second segment. In this case, the receiver cannot acknowledge the second packet. It can only send AckNo=1501, after receiving 1st segment
  • 39. TCP Header Fields • Header Length (4bits): – Length of header in 32-bit words – Note that TCP header has variable length (with minimum 20 bytes)
  • 40. TCP Header Fields • Flag bits: – URG: Urgent pointer is valid – If the bit is set, the following bytes contain an urgent message in the range: SeqNo <= urgent message <= SeqNo+urgent pointer – ACK: Acknowledgement Number is valid – PSH: PUSH Flag – Notification from sender to the receiver that the receiver should pass all data that it has to the application. – Normally set by sender when the sender’s buffer is empty
  • 41. TCP Header Fields • Flag bits: – RST: Reset the connection – The flag causes the receiver to reset the connection – Receiver of a RST terminates the connection and indicates higher layer application about the reset – SYN: Synchronize sequence numbers – Sent in the first packet when initiating a connection – FIN: Sender is finished with sending – Used for closing a connection – Both sides of a connection must send a FIN
  • 42. TCP Header Fields • Window Size: – Each side of the connection advertises the window size – Window size is the maximum number of bytes that a receiver can accept. – Maximum window size is 216 -1= 65535 bytes • TCP Checksum: – TCP checksum covers over both TCP header and TCP data (also covers some parts of the IP header) • Urgent Pointer: – Only valid if URG flag is set
  • 43. TCP Header Fields • Options: End of Options kind=0 1 byte NOP (no operation) kind=1 1 byte Maximum Segment Size kind=2 1 byte len=4 1 byte maximum segment size 2 bytes Window Scale Factor kind=3 1 byte len=3 1 byte shift count 1 byte Timestamp kind=8 1 byte len=10 1 byte timestamp value 4 bytes timestamp echo reply 4 bytes
  • 44. TCP Header Fields • Options: – NOP is used to pad TCP header to multiples of 4 bytes – Maximum Segment Size – Window Scale Options » Increases the TCP window from 16 to 32 bits, I.e., the window size is interpreted differently Q: What is the different interpretation ? » This option can only be used in the SYN segment (first segment) during connection establishment time – Timestamp Option » Can be used for roundtrip measurements
  • 45. Pseudoheader Added To The TCP Datagram
  • 46. Window size: This field defines the window size of the sending TCP in bytes. Checksum: The calculation of the checksum for TCP follows the same procedure as UDP. Using checksum in the UDP datagram is optional, but in TCP it’s mandatory. The same pseudoheader, serving the same purpose, is added to the segment. For the TCP pseudoheader, the value for the protocol field is 6. Urgent pointer. This 16-bit field, which is valid only if the urgent flag is set, is used when the segment contains urgent data. Options. There can be up to 40 bytes of optional information in the TCP header. Pseudoheader Added To The TCP Datagram