You are on page 1of 23

TCP and UDP

Facilitator: Parvesh Mor

Transport Layer Overview

Application
Transport
Internet

Transmission Control
Protocol (TCP)

ConnectionOriented

User Datagram
Protocol (UDP)

Connectionless

Data-Link
Physical

TCP Segment Format


Bit 0

Bit 15 Bit 16
Source Port (16)

Bit 31
Destination Port (16)

Sequence Number (32)


Acknowledgment Number (32)
Header
Length (4)

Reserved (6) Code Bits (6)


Checksum (16)

20
Bytes

Window (16)
Urgent (16)

Options (0 or 32 if Any)
Data (Varies)
3

Port Numbers

Application
Layer

Transport
Layer

F
T
P

T
E
L
N
E
T

S
M
T
P

D
N
S

T
F
T
P

S
N
M
P

R
I
P

21

23

25

53

69

161

520

TCP

UDP

Port
Numbers
4

TCP Port Numbers


Source
Port

Telnet Z

Destination
Port

Host Z

Host A

SP

DP

1028

23

Destination port = 23.


Send packet to my
Telnet
application.
5

TCP Port Numbers

TCP Three-Way
Handshake/Open Connection
Host A

Send SYN
(seq = 100 ctl = SYN)

SYN Received

Established
(seq = 101 ack = 301
ctl = ack)

Host B

SYN Received
Send SYN, ACK 2
(seq = 300 ack = 101
ctl = syn,ack)

TCP Connection Establishment


TCP uses a three-way handshake to open a connection:
(1) ACTIVE OPEN: Client sends a segment with
SYN bit set *
port number of client
initial sequence number (ISN) of client
(2) PASSIVE OPEN: Server responds with a segment with
SYN bit set *
initial sequence number of server
ACK for ISN of client
(3) Client acknowledges by sending a segment with:
ACK ISN of server
(* counts as one byte)
8

Opening & Closing Connection

TCP States in Normal Connection


Lifetime
LISTEN

SYN_SENT

(passive open)

(active open)

SYN_RCVD

ESTABLISHED
ESTABLISHED
FIN_WAIT_1
(active close)

CLOSE_WAIT
(passive close)

FIN_WAIT_2

LAST_ACK
TIME_WAIT
CLOSED

10

TCP States
State

Description

CLOSED
LISTEN
SYN RCVD
SYN SENT
ESTABLISHED
FIN WAIT 1
FIN WAIT 2
TIMED WAIT
CLOSING
CLOSE WAIT
LAST ACK

No connection is active or pending


The server is waiting for an incoming call
A connection request has arrived; wait for Ack
The client has started to open a connection
Normal data transfer state
Client has said it is finished
Server has agreed to release
Wait for pending packets (2MSL wait state)
Both Sides have tried to close simultanesously
Server has initiated a release
Wait for pending packets

Windowing
Windowing in networking means the quantity of data segments
which is measured in bytes that a machine can transmit/send on
the network without receiving an acknowledgement

12

TCP Simple Acknowledgment


Sender

Receiver

Send 1

Receive 1
Send ACK 2

Receive ACK 2
Send 2

Receive 2
Send ACK 3

Receive ACK 3
Send 3

Receive 3
Send ACK 4

Receive ACK 4
Window Size = 1

13

TCP Sequence and


Acknowledgment Numbers
Source
Port

Destination
Port

Acknowledgment

Sequence

I just
sent number
11.

I just got number


11, now I need
number 12.

Source Dest.
Dest. Seq.
Seq. Ack.
Ack.
1028

23

10
10

100

Source Dest. Seq. Ack.


23

1028

23

11
11

101

1028

100

11
11

Source Dest. Seq. Ack.


23

1028

101

12
12

14

Windowing
There are two window sizesone set to 1 and one set to 3.
When youve configured a window size of 1, the sending machine
waits for an acknowledgment for each data segment it transmits
before transmitting another
If youve configured a window size of 3, its allowed to transmit
three data segments before an acknowledgment is received.

15

Windowing

16

Transport Layer Reliable Delivery

17

Flow Control
Another function of the transport layer is to provide optional flow
control.
Flow control is used to ensure that networking devices dont send
too much information to the destination, overflowing its receiving
buffer space, and causing it to drop the sent information
The purpose of flow control is to ensure the destination doesn't get
overrun by too much information sent by the source

18

Flow Control
A

SEQ 1024 3
SEQ 2048

3072
B

SEQ 3072
in 0
W
073
3
Ack

in
W
073
3
Ack 3072
19

User Datagram Protocol (UDP)


User Datagram Protocol (UDP) is the connectionless transport
protocol in the TCP/IP protocol stack.
UDP is a simple protocol that exchanges datagrams, without
acknowledgments or guaranteed delivery. Error processing and
retransmission must be handled by higher layer protocols.
UDP is designed for applications that do not need to put
sequences of segments together.
The protocols that use UDP include:

TFTP (Trivial File Transfer Protocol)

SNMP (Simple Network Management Protocol)

DHCP (Dynamic Host Control Protocol)

DNS (Domain Name System)


20

UDP Segment Format


Bit
1 0

Bit 15 Bit 16
Source Port (16)

Bit 31
Destination Port (16)

Length (16)

Checksum (16)

8
Bytes

Data (if Any)

No sequence or acknowledgment fields

21

TCP vs UDP

22

Common UDP Application & Ports

53- Domain DNS


67,68 BOOTP & DHCP respectively
69 TFTP
161,162 SNMP
520,521 RIPv1,RIPv2
2049 NFS

23

You might also like