TCP UDP
multiplexing/
demultiplexing
Encapsulation at sender:
z Process passes the message to UDP along with a pair of
socket address and length of data.
z UDP adds UDP header to the data.
z UDP passes the user datagram to the IP with the socket
addresses.
z IP adds its own header, using the value 17 in the protocol
field - indicates that the data has come from UDP.
Decapsulation at receiver:
z UDP receives the data from the IP software.
z UDP uses the checksum to detect error.
z If no error, UDP passes the message along with the sender
socket address to the process.
Multiplexing/Demultiplexing:
z Needed because there may be several processes that need
to send/receive user datagrams, but there is only one UDP
per host.
TCP:
z Includes all UDP service elements:
encapsulation/decapsulation.
queuing.
multiplexing/demultiplexing.
z Plus additional service elements:
connection management
error control: recover lost/damaged segments
flow control: sender will not overwhelm the receiver
congestion control: sender will not overwhelm the
network
Format:
z Source port number: port number used by the process
running on the source host.
z Destination port number: port number used by the process
running on the destination host.
z Sequence number: the number assigned to the first byte of
data contained in this segment.
TCP is a stream protocol - to ensure connectivity, each
byte is numbered.
For example:
the sequence number for segment N is 2367 and the
segment carries 1,000 bytes
the sequence number for segment N+1 is 2367+1000 =
3367
Used for checking lost segments and flow control
CSC4430 – Data Communication and Computer Networks 30
17.4. TCP: Transmission Control Protocol
Format:
z Acknowledgement number: defines the number of the next
byte of data expected from the source.
For example:
byte number x has successfully received, then the receiver
will defines x+1 as the acknowledgement number.
it then piggybacks the number in the data it sends to the
source of the segment.
z Header length: indicates the number of four-byte words in
the header.
Header length can be between 20-60 bytes.
So the value of the field range 5-15.
z Reserved: this field is reserved for future use.
Format:
z Control: defines six different control bits or flags.
URG: urgent data (generally not used)
ACK: acknowledgement is valid
PSH: push data now (generally not used)
RST: reset the connection
SYN: synchronize sequence numbers during connection
FIN: terminate the connection
RST, SYN, FIN are used for connection management
Format:
z Window size: defines the size of receiver window, in bytes
Maximum size of the window is 65,535 bytes = maximum
TCP segment
z Checksum: contains the checksum
TCP checksum is mandatory, cf. UDP checksum is
optional.
Operates in the same way as UDP checksum.
z Urgent pointer: used when the segment contains urgent
data, i.e. when URG flag is set.
z Option: allows optional information to be conveyed to the
receiver.
TCP:
z Basic service elements operate in the same way
as UDP
encapsulation/decapsulation
queuing
multiplexing/demultiplexing
z Additional service elements:
connection management
error control: recover lost/damaged segments
flow control: sender will not overwhelm the receiver
congestion control: sender will not overwhelm the
network
Three-way handshaking:
Host A Host B
Three-way handshaking:
c Host A sends a SYN segment - initialization message.
contains Host A initialization sequence number (ISN)
ISN is used for numbering the bytes of data send by Host A.
Host A and Host B may have different ISN.
can also include maximum segment size (MSS) it can
receive from Host B.
d Host B sends a SYN+ACK segment.
acknowledges the receipt of SYN segment from Host A
using the ACK flag and acknowledgement number field.
acknowledgement number = Host A ISN + 1
sends its own initialization parameters to Host A.
Host A sends an ACK segment.
acknowledges the receipt of SYN segment from Host B
can also include data
CSC4430 – Data Communication and Computer Networks 38
17.4.2.2. Connection Termination
Four-way handshaking:
Host A Host B
closing
closing
timed wait
closed
closed
Four-way handshaking:
c Host A sends a FIN segment and closes the connection.
d Host B sends an ACK segment.
acknowledges the receipt of FIN segment from Host A
using the ACK flag and acknowledgement number field.
Host B can continue sending data to Host A.
e Host B sends a FIN segment and closes the connection.
acknowledges the receipt of FIN segment from Host A
using the ACK flag and acknowledgement number field.
f Host A sends an ACK segment
acknowledges the receipt of FIN segment from Host B
enters “time-wait” - allows it to send out
acknowledgement if it receives FINs from Host B.
z For example:
The client TCP starts in the CLOSED state.
If it receive an active open request from the client
application program:
it sends a SYN segment to server TCP.
it goes to the SYN-SENT state.
CLOSED SYN-SENT
TCP states
48