0% found this document useful (0 votes)
11 views29 pages

ESET315 Lecture TCP Fall24

Uploaded by

bsporras04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views29 pages

ESET315 Lecture TCP Fall24

Uploaded by

bsporras04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

ESET 315 – Advanced Networking

& Security

Transport Layer – TCP and Socket


Programming

Instructor: Dr. Ana Goulart

Texas A&M - ETID Department – 1


ESET 315
TCP/IP Architecture

TCP/UDP

IP

Ethernet,
Wi-Fi,
Cellular,
etc
2
TCP and UDP are end-to-end protocols
• Let’s draw the communication from Host A1 to Host B
using the OSI layers Please submit your drawing in Canvas.

3
Functionality of Transport Layer
Protocols
• Multiplexing
UDP
• Error Checking TCP
• Reliability
• Rate Control (Flow congestion control)

Electronics & 4 UDP


Telecommunications
UDP – a Simple Demultiplexer

Texas A&M - ETID Department - 5


Protocol Multiplexing
Layer 2 – Type field
Layer 3 – Protocol field
Layer 4 - ?

application …… application application …… application

Port
TCP UDP numbers

ICMP
Protocol
IP
Field
ARP RARP

Type
Field
Ethernet
Driver

Incoming
Electronics & 6frame UDP
Data
Telecommunications
TCP X UDP

Internet B
A

End-to-End

TCP UDP
Reliable Unreliable
(acknowledgements and
retransmissions)
Connection-oriented Connectionless
service datagram service
7
UDP Packet Header

Texas A&M - ETID Department 8


TCP is the “big brother” of IP
• Reliable byte stream
• A TCP packet is called a Segment
• Sequence number: TCP numbers Bytes, not segments
Services provided by TCP
• Connection-oriented
• Reliable – no loss
• Re-order the data (if TCP segments arrive out-of-order)
• Full duplex

• TCP is an ARQ protocol


– Transmissions
– Acknowledgements
– Timeout and retransmissions

Electronics & 10 UDP


Telecommunications
TCP Connection Handshake
( “let’s synchronize our sequence numbers”)
A B

Events at A
Events at B
Connect SYN=1, initial sequence number (ISN) = X

SYN=1, initial sequence number (ISN) = Y, ACK = Accept


X+1

3-way
Handshake
Acknowledge SYN=0, initial sequence number (ISN) = X+1,
algorithm
Accept ACK = Y+1

Electronics & 11 UDP


Telecommunications
TCP Connection Termination
A B

Events at A
Events at B
Close FIN=1, Seq = X

ACK = X+1 Acknowledge


Data can be sent
From B to A during
This period
FIN=1, Seq = Y
Close

Acknowledge ACK = Y+1

Electronics & SYN=0, initial sequence


12 number = Y+1 UDP
Telecommunications
Socket
Programming

TCP Server

Texas A&M - ETID Department – 13


ESET 415
Socket
Programming

TCP Client

Texas A&M - ETID Department - 14


ESET 415
Source and Destination Port Numbers:
identify the sending and receiving application

What identifies a connection?


source port, Socket
source IP address,
destination port, Socket
destination IP address
SOURCE PORT DESTINATION PORT
SEQUENCE NUMBER
ACKNOWLEDGEMENT NUMBER
HLEN RESERVED CODE BITS WINDOW
CHECKSUM URGENT POINTER
OPTIONS (IF ANY) PADDING
DATA

Electronics &

15 UDP
Telecommunications
TCP Demultiplexing
Application 1 Application 2 Application 3
Port 1 Port 2 Port 3

TCP: Demultiplexing
Based On Port

TCP Packet Arrives

IP Layer

Electronics & 16 TCP


Telecommunications
Source and Destination Port Numbers:
identify the sending and receiving application

What identifies a connection?


source port, Socket
source IP address,
destination port, Socket
destination IP address
SOURCE PORT DESTINATION PORT
SEQUENCE NUMBER
ACKNOWLEDGEMENT NUMBER
HLEN RESERVED CODE BITS WINDOW
CHECKSUM URGENT POINTER
OPTIONS (IF ANY) PADDING
DATA

Electronics &

17 UDP
Telecommunications
TCP is a sliding-window ARQ protocol:

Sequence number (SN) – the first byte of data in the TCP segment
TCP numbers each byte with a SN
maximum: 2 32 – 1 (wraps around)
Acknowledgement number – the next sequence number that the sender
of ack expects to receive
Window size – number of bytes that the receiver can accept (buffer space)

SOURCE PORT DESTINATION PORT


SEQUENCE NUMBER
ACKNOWLEDGEMENT NUMBER
HLEN RESERVED CODE BITS WINDOW
CHECKSUM URGENT POINTER
OPTIONS (IF ANY) PADDING
DATA

Electronics &

18 UDP
Telecommunications
TCP Header (Code Bits)
0 4 10 16 24 31
SOURCE PORT DESTINATION PORT
SEQUENCE NUMBER
ACKNOWLEDGEMENT NUMBER
HLEN RESERVED CODE BITS WINDOW
CHECKSUM URGENT POINTER
OPTIONS (IF ANY) PADDING
DATA
URG: The urgent pointer is valid
ACK: The acknowledgment number is valid …
PSH: the receiver should pass this data to the
application as soon as possible U A P R S FI
RST: Reset the connection R C S ST Y N
SYN: Synchronize sequence numbers to initiate a
G K H N
connection.
FIN: The sender
Electronics & is finished sending data. 19 UDP
Telecommunications
TCP Transmission Example
Window = 16 bytes
DATA, SEQ=64, ACK=28, (16 bytes of data)
16 bytes of data
received
ACK = 80, Window = 8

Window = 8 bytes
DATA, SEQ=80, ACK=28, (8 bytes of data)
8 bytes of data
ACK = 88, Window = 8 received

DATA, SEQ=88, ACK=28, (8 bytes of data)


Still expecting
Timer expires SEQ=88
(RETRANSMIT) DATA, SEQ=88, ACK=28, (8 bytes
(no ACK received) of data) 8 bytes of data
ACK = 96, Window = 8 received
Electronics & 20
Telecommunications
Urgent Pointer is used to transmit
emergency data
0 4 10 16 24 31
SOURCE PORT DESTINATION PORT
SEQUENCE NUMBER
ACKNOWLEDGEMENT NUMBER
HLEN RESERVED CODE BITS WINDOW
CHECKSUM URGENT POINTER
OPTIONS (IF ANY) PADDING
DATA

Urgent pointer – is a positive offset that must be added to the sequence


number field of the segment to indicate the last byte of urgent data.

Electronics & 21 UDP


Telecommunications
TCP Header - Options field
0 4 10 16 24 31
SOURCE PORT DESTINATION PORT
SEQUENCE NUMBER
ACKNOWLEDGEMENT NUMBER
HLEN RESERVED CODE BITS WINDOW
CHECKSUM URGENT POINTER
OPTIONS (IF ANY) PADDING
DATA

Common option field: MSS – Maximum Segment Size

If Options is used, HLEN = 6 or more (units of 32-bit words)


Electronics & 22 UDP
Telecommunications
TCP Header (Code Bits)
0 4 10 16 24 31
SOURCE PORT DESTINATION PORT
SEQUENCE NUMBER
ACKNOWLEDGEMENT NUMBER
HLEN RESERVED CODE BITS WINDOW
CHECKSUM URGENT POINTER
OPTIONS (IF ANY) PADDING
DATA
URG: The urgent pointer is valid
ACK: The acknowledgment number is valid …
PSH: the receiver should pass this data to the
application as soon as possible U A P R S FI
RST: Reset the connection R C S ST Y N
SYN: Synchronize sequence numbers to initiate a
G K H N
connection.
FIN: The sender
Electronics & is finished sending data. 23 UDP
Telecommunications
TCP Header - Options field
0 4 10 16 24 31
SOURCE PORT DESTINATION PORT
SEQUENCE NUMBER
ACKNOWLEDGEMENT NUMBER
HLEN RESERVED CODE BITS WINDOW
CHECKSUM URGENT POINTER
OPTIONS (IF ANY) PADDING
DATA

Common option field: MSS – Maximum Segment Size

If Options is used, HLEN = 6 (units of 32-bit words)


Electronics & 24 UDP
Telecommunications
TCP Maximum Segment Size
(MSS)
TCP Max Segment: Size: ?

Layer 4 TCP
HEADER
TCP Data Area

20 bytes

Layer 3 IP
HEADER
IP DATA AREA
20 bytes 1480 bytes

FRAME
HEADER
FRAME DATA AREA CRC

MTU = 1500 bytes


25
Example
• Illustrate how a file is transferred from computer A to
computer B using TCP. Use the following information:

– File size = 4000 bytes


– Maximum segment size (MSS) = 512 bytes
– The first packet is sent with sequence number 12000.
– The receiver’s window size is initially set to 2048 bytes. After the
first 4 packets, the receiver’s window size decreases to 1024
bytes.

• Clearly show how the sliding window is dynamically


changed. Show the acknowledgment numbers and
sequence numbers as well.
Case 1: Receiver waits and then sends
acknowledgement for the last packet in the window
A B
SN = 12000 (512 bytes of data)
pkt1
Window size = 2048 bytes
SN = 12512 (512 bytes of data)
pkt2
SN = 13024 (512 bytes of data) = 4 packets waiting for ack
pkt3
SN = 13536 (512 bytes of data)
pkt4
Window size = 1024 bytes
ACK = 14048, W=1024
Ack for pkts 1,2, 3, 4
SN = 14048 (512 bytes of data)
pkt5
SN = 14560 (512 bytes of data) = 2 packets waiting for ack
pkt6
ACK = 15072
Ack for pkts 5,6
SN = 15072 (512 bytes of data)
pkt7
SN = 15584 (416 bytes of data) = 2 packets waiting for ack
pkt8

Ack for pkts 7, 8


ACK = 16000
Case 2: Receiver sends acknowledgement
randomly B
A
pkt1 SN = 12000 (512 bytes of data)
Window size = 2048 bytes
pkt2 SN = 12512 (512 bytes of data)
= 4 packets waiting for ack
pkt3 SN = 13024 (512 bytes of data)

pkt4 SN = 13536 (512 bytes of data)

ACK = 13536 Window size = 1024 bytes


= 2 packets waiting for ack
Ack for pkts 1,2,and 3
SN = 14048 (512 bytes of data)
pkt5
ACK = 14048, W=1024
Ack for pkt 4 = 2 packets waiting for ack
SN = 14560 (512 bytes of data)
pkt6
ACK = 15072
Ack for pkts 5 and 6
pkt7 SN = 15072 (512 bytes of data)

pkt8 SN = 15584 (416 bytes of data) = 2 packets waiting for ack

ACK = 16000
Ack for pkts 7 and 8
Questions?

For next class:

- Reading Assignments for this week:

-Peterson, Chapter 5
- Section 5.1 – Simple Demultiplexer (UDP)
- Section 5.2 – Reliable Byte Stream (TCP)
- 5.2.3 – Connection Establishment and Termination (pages
402 to 404

Texas A&M - ETID Department – 29


ESET 415

You might also like