Declaration
Reference: Andrew S. Tanenbaum - Computer Networks
• This Lecture Material is prepared for
Delivering Data Transmission by ML
• Notes were taken from Text Book: “Andrew
S. Tanenbaum - Computer Networks”
•
5/7/2024 1
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
2
Outline
Transmission Control Protocol
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
3
Transport Layer 1/2
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
4
Transport Layer 2/2
Process-to-process delivery
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
5
Transport Layer Addressing
Addresses
•Data link layer  MAC address
•Network layer  IP address
•Transport layer  Port number (choose among multiple
processes running on destination host)
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
6
Port Numbers
•Port numbers are 16-bit integers (0  65,535)
Servers use well know ports, 0-1023 are privileged
Clients use ephemeral (short-lived) ports
•Internet Assigned Numbers Authority (IANA) maintains a list of
port number assignment
Well-known ports (0-1023)  controlled and assigned by
IANA
Registered ports (1024-49151)  IANA registers and lists
use of ports as a convenience (49151 is ¾ of 65536)
Dynamic ports (49152-65535)  ephemeral ports
For well-known port numbers, see /etc/services on a UNIX or
Linux machine
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
7
Socket Addressing
•Process-to-process delivery needs two identifiers
IP address and Port number
Combination of IP address and port number is called a
socket address (a socket is a communication endpoint)
Client socket address uniquely identifies client process
Server socket address uniquely identifies server process
•Transport-layer protocol needs a pair of socket addresses
Client socket address
Server socket address
For example, socket pair for a TCP connection is a 4-tuple
Local IP address, local port, and
foreign IP address, foreign port
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
8
Multiplexing and Demultiplexing
Multiplexing
Sender side may have
several processes that
need to send packets
(albeit only 1 transport-
layer protocol)
Demultiplexing
At receiver side, after
error checking and
header dropping,
transport-layer delivers
each message to
appropriate process
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
9
Transmission Control Protocol 1/10
•TCP must perform typical transport layer functions:
Segmentation  breaks message into packets
End-to-end error control since IP is an unreliable Service
End-to-end flow control  to avoid buffer overflow
Multiplexing and demultiplexing sessions
•TCP is [originally described in RFC 793, 1981]
Reliable
Connection-oriented  virtual circuit
Stream-oriented  users exchange streams of data
Full duplex  concurrent transfers can take place in both
directions
Buffered  TCP accepts data and transmits when appropriate
(can be overridden with “push”)
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
10
Transmission Control Protocol 2/10
•Reliable
requires ACK and performs retransmission
If ACK not received, retransmit and wait a longer time for
ACK. After a number of retransmissions, will give up
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
11
Transmission Control Protocol 5/10
•TCP uses a sliding window mechanism for flow control
•Sender maintains 3 pointers for each connection
Pointer to bytes sent and acknowledged
Pointer to bytes sent, but not yet acknowledged
Sender window includes bytes sent but not acknowledged
Pointer to bytes that cannot yet be sent
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
12
Transmission Control Protocol 6/10
•Flow Control
Tell peer exactly how many bytes it is willing to accept
(advertised window  sender can not overflow receiver buffer)
Sender window includes bytes sent but not acknowledged
Receiver window (number of empty locations in receiver buffer)
Receiver advertises window size in ACKs
Sender window <= receiver window (flow control)
Sliding sender window (without a change in receiver’s advertised
window)
Expanding sender window (receiving process consumes data faster than
it receives  receiver window size increases)
Shrinking sender window (receiving process consumes data more
slowly than it receives  receiver window size reduces)
Closing sender window (receiver advertises a window of zero)
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
13
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
14
Transmission Control Protocol 6/10
•Flow Control
TCP Flow Control
□receive side of TCP connection has a receive buffer:
□ The app process may be slow at reading from buffer
flow control
sender won’t overflow receiver’s
buffer by transmitting too much, too
fast
□speed-matching service: matching the send rate to
the receiving app’s drain rate
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
15
Transmission Control Protocol 6/10
•Flow Control
TCP Flow control: how it works
(Suppose TCP receiver
discards out-of-
order segments)
□spare room in buffer
= RcvWindow
= RcvBuffer-[LastByteRcvd
- LastByteRead]
□ Rcvr advertises spare room by
including value of RcvWindow in
segments
Sender limits unACKed data to
RcvWindow
0 guarantees receive buffer doesn’t
overflow
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
16
TCP Connection Establishment
SYN: Synchronize
ACK: Acknowledge
Three way handshake:
Step 1: client host sends TCP SYN segment to
server
O specifies initial seq #
O no data
Step 2: server host receives SYN, replies with
SYNACK segment
O server allocates buffers
O specifies server initial seq. #
Step 3: client receives SYNACK, replies with ACK
segment, which may contain data
Recall: TCP sender, receiver
establish “connection” before
exchanging data segments
□ initialize TCP variables:
O seq. #s
O buffers, flow control info (e.g.
RcvWindow)
□ client: connection
initiator Socket clientSocket =
new Socket("hostname","port
number");
□ server: contacted by
client Socket connectionSocket =
welcomeSocket.accept();
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
17
TCP Connection Establishment
Closing a connection:
client closes socket:
clientSocket.close();
Step 1: client end system sends TCP FIN
control segment to server
Step 2: server receives FIN, replies with
ACK. Closes connection, sends FIN.
Step 3: client receives FIN, replies with
ACK.
O Enters “timed wait” - will respond with ACK to
received FINs
Step 4: server, receives ACK. Connection
closed.
Note: with small modification, can handle
simultaneous FINs.
client server
close
timed
wait
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
18
State Transition Diagram 1/4
Typical TCP
states visited
by a TCP
client
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
19
State Transition Diagram 2/4
Typical
TCP
states
visited by
a TCP
server
5/7/2024 Reference: Andrew S. Tanenbaum - Computer
Networks
20
State Transition Diagram 3/4
State Description
CLOSED There is no connection.
LISTEN The server is waiting for calls from the client.
SYN-SENT A connection request is sent; waiting for acknowledgment.
SYN-RCVD A connection request is received.
ESTABLISHED Connection is established.
FIN-WAIT-1
The application has requested the closing of the
connection.
FIN-WAIT-2 The other side has accepted the closing of the connection.
TIME-WAIT Waiting for retransmitted segments to die.
CLOSE-WAIT The server is waiting for the application to close.
LAST-ACK The server is waiting for the last acknowledgment.
Can use netstat command to see some TCP states

Data Transmission flow using TCP protocol

  • 1.
    Declaration Reference: Andrew S.Tanenbaum - Computer Networks • This Lecture Material is prepared for Delivering Data Transmission by ML • Notes were taken from Text Book: “Andrew S. Tanenbaum - Computer Networks” • 5/7/2024 1
  • 2.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 2 Outline Transmission Control Protocol
  • 3.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 3 Transport Layer 1/2
  • 4.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 4 Transport Layer 2/2 Process-to-process delivery
  • 5.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 5 Transport Layer Addressing Addresses •Data link layer  MAC address •Network layer  IP address •Transport layer  Port number (choose among multiple processes running on destination host)
  • 6.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 6 Port Numbers •Port numbers are 16-bit integers (0  65,535) Servers use well know ports, 0-1023 are privileged Clients use ephemeral (short-lived) ports •Internet Assigned Numbers Authority (IANA) maintains a list of port number assignment Well-known ports (0-1023)  controlled and assigned by IANA Registered ports (1024-49151)  IANA registers and lists use of ports as a convenience (49151 is ¾ of 65536) Dynamic ports (49152-65535)  ephemeral ports For well-known port numbers, see /etc/services on a UNIX or Linux machine
  • 7.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 7 Socket Addressing •Process-to-process delivery needs two identifiers IP address and Port number Combination of IP address and port number is called a socket address (a socket is a communication endpoint) Client socket address uniquely identifies client process Server socket address uniquely identifies server process •Transport-layer protocol needs a pair of socket addresses Client socket address Server socket address For example, socket pair for a TCP connection is a 4-tuple Local IP address, local port, and foreign IP address, foreign port
  • 8.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 8 Multiplexing and Demultiplexing Multiplexing Sender side may have several processes that need to send packets (albeit only 1 transport- layer protocol) Demultiplexing At receiver side, after error checking and header dropping, transport-layer delivers each message to appropriate process
  • 9.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 9 Transmission Control Protocol 1/10 •TCP must perform typical transport layer functions: Segmentation  breaks message into packets End-to-end error control since IP is an unreliable Service End-to-end flow control  to avoid buffer overflow Multiplexing and demultiplexing sessions •TCP is [originally described in RFC 793, 1981] Reliable Connection-oriented  virtual circuit Stream-oriented  users exchange streams of data Full duplex  concurrent transfers can take place in both directions Buffered  TCP accepts data and transmits when appropriate (can be overridden with “push”)
  • 10.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 10 Transmission Control Protocol 2/10 •Reliable requires ACK and performs retransmission If ACK not received, retransmit and wait a longer time for ACK. After a number of retransmissions, will give up
  • 11.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 11 Transmission Control Protocol 5/10 •TCP uses a sliding window mechanism for flow control •Sender maintains 3 pointers for each connection Pointer to bytes sent and acknowledged Pointer to bytes sent, but not yet acknowledged Sender window includes bytes sent but not acknowledged Pointer to bytes that cannot yet be sent
  • 12.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 12 Transmission Control Protocol 6/10 •Flow Control Tell peer exactly how many bytes it is willing to accept (advertised window  sender can not overflow receiver buffer) Sender window includes bytes sent but not acknowledged Receiver window (number of empty locations in receiver buffer) Receiver advertises window size in ACKs Sender window <= receiver window (flow control) Sliding sender window (without a change in receiver’s advertised window) Expanding sender window (receiving process consumes data faster than it receives  receiver window size increases) Shrinking sender window (receiving process consumes data more slowly than it receives  receiver window size reduces) Closing sender window (receiver advertises a window of zero)
  • 13.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 13
  • 14.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 14 Transmission Control Protocol 6/10 •Flow Control TCP Flow Control □receive side of TCP connection has a receive buffer: □ The app process may be slow at reading from buffer flow control sender won’t overflow receiver’s buffer by transmitting too much, too fast □speed-matching service: matching the send rate to the receiving app’s drain rate
  • 15.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 15 Transmission Control Protocol 6/10 •Flow Control TCP Flow control: how it works (Suppose TCP receiver discards out-of- order segments) □spare room in buffer = RcvWindow = RcvBuffer-[LastByteRcvd - LastByteRead] □ Rcvr advertises spare room by including value of RcvWindow in segments Sender limits unACKed data to RcvWindow 0 guarantees receive buffer doesn’t overflow
  • 16.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 16 TCP Connection Establishment SYN: Synchronize ACK: Acknowledge Three way handshake: Step 1: client host sends TCP SYN segment to server O specifies initial seq # O no data Step 2: server host receives SYN, replies with SYNACK segment O server allocates buffers O specifies server initial seq. # Step 3: client receives SYNACK, replies with ACK segment, which may contain data Recall: TCP sender, receiver establish “connection” before exchanging data segments □ initialize TCP variables: O seq. #s O buffers, flow control info (e.g. RcvWindow) □ client: connection initiator Socket clientSocket = new Socket("hostname","port number"); □ server: contacted by client Socket connectionSocket = welcomeSocket.accept();
  • 17.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 17 TCP Connection Establishment Closing a connection: client closes socket: clientSocket.close(); Step 1: client end system sends TCP FIN control segment to server Step 2: server receives FIN, replies with ACK. Closes connection, sends FIN. Step 3: client receives FIN, replies with ACK. O Enters “timed wait” - will respond with ACK to received FINs Step 4: server, receives ACK. Connection closed. Note: with small modification, can handle simultaneous FINs. client server close timed wait
  • 18.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 18 State Transition Diagram 1/4 Typical TCP states visited by a TCP client
  • 19.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 19 State Transition Diagram 2/4 Typical TCP states visited by a TCP server
  • 20.
    5/7/2024 Reference: AndrewS. Tanenbaum - Computer Networks 20 State Transition Diagram 3/4 State Description CLOSED There is no connection. LISTEN The server is waiting for calls from the client. SYN-SENT A connection request is sent; waiting for acknowledgment. SYN-RCVD A connection request is received. ESTABLISHED Connection is established. FIN-WAIT-1 The application has requested the closing of the connection. FIN-WAIT-2 The other side has accepted the closing of the connection. TIME-WAIT Waiting for retransmitted segments to die. CLOSE-WAIT The server is waiting for the application to close. LAST-ACK The server is waiting for the last acknowledgment. Can use netstat command to see some TCP states