2. OSI Model TCP/IP Hierarchy Protocols
7th
Application Layer
6th
Presentation Layer
5th
Session Layer
4th
Transport Layer
3rd
Network Layer
2nd
Link Layer
1st
Physical Layer
Application Layer
Transport Layer
Network Layer
Link Layer
OSI v/s TCP/IP
3. Transmission Control Protocol
(TCP)
Major transport service in the TCP/IP suite
Used for most Internet applications (esp. World Wide Web)
Connection-oriented protocol
Provides a reliable unicast end-to-end byte stream over an unreliable
internetwork.
Very complex
• Specifies format of data and acks
• Specifies how TCP software distinguishes among multiple destinations on a host
• How hosts recover from lost or duplicated packets
• How hosts initiate and terminate a transfer TCP
IP Internetwork
ByteStream
ByteStream
TCP
5. Providing Reliability
Traditional technique: Positive Acknowledgement with
Retransmission (PAR)
• Receiver sends acknowledgement when data arrives
• Sender starts timer whenever transmitting
• Sender retransmits if timer expires before
• acknowledgement arrives
6. Illustration Of Sliding Window
Window size is fixed
As acknowledgement arrives, window moves forward
Why Sliding Window Works
Because a well-tuned sliding window protocol keeps
the network completely saturated with packets, it obtains
substantially higher throughput than a simple positive
acknowledgement protocol.
8. Conceptual Layering Layering Of The Three
Major Protocols
Application
Reliable Stream (TCP) User Datagram (UDP)
Internet (IP)
Network Interface
9. Ports, Connections, and Endpoints
Like UDP, TCP resides in the transport layer
Like UDP, TCP uses protocol port numbers to identify
the ultimate destination within a host
TCP ports are much more complex than UDP ports
TCP port numbers do not correspond to a single object.
TCP is built on the connection abstraction, in which
objects are identified by connections.
A connection is a pair of endpoints.
An endpoint is a pair, (host, port).
Two connections might share one endpoint.
10. TCP connection between two endpoints identified by
four items
Sender’s IP address
Sender’s protocol port number
Receiver’s IP address
Receiver’s protocol port number
An Important Idea About Port Numbers
• Because TCP identifies a connection by a pair of
endpoints, a given TCP port number can be shared by
multiple connections on the same machine.
11. Passive And Active Opens
Two sides of a connection
One side waits for contact
• A server program
• Uses TCP’s passive open
One side initiates contact
• A client program
• Uses TCP’s active open
12. Passive and Active Opens(cntd)
• An application program on one end performs a passive open by
indicating to the OS that it will accept an incoming connection. The OS
provides a TCP port number for its end of the connection.
• An application program on the other end uses an active open request a
connection.
• The two TCP software modules communicate to establish and verify
a connection.
• Once the connection is established, the application programs begin
to pass data.
• TCP modules at each end guarantee reliable delivery.
13. Segments, Streams, and Sequence Numbers
TCP views the data as a sequence of octets that it divides into segments.
Usually, each segment travels in a single IP datagram.
TCP uses a specialized sliding window mechanism to solve two
problems: efficient transmission and flow control.
TCP allows the receiver to restrict transmission until it has sufficient
buffer space to accommodate more data.
The sliding window mechanism operates the octet level. A sender keeps
three pointers associated with each connection.
TCP software at each end maintains two windows per connection
for a total of four.
One slides as data is sent, the other as data is
received.
14. Variable Window Size and Flow Control
TCP allows the window size to vary over time. Each ack contains a
window advertisement that specifies how many octets of data the
receiver is prepared to accept.
This provides flow control. The window size may even be zero.
When intermediate machines become overloaded, the condition is
called congestion, and mechanisms to solve the problem are called
congestion control mechanisms.
Solves two independent problems.
• A hand-held PDA communicating with a fast PC may be overrun.
•A mechanism is needed to allow intermediate systems (routers) to
control a source that sends more traffic than the system can tolerate.
15. TCP Segment 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
20bytes
16. 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, server port
number> and <server IP address, server port
number> identify a TCP connection.
TCP
IP
Applications
23 10480Ports:
TCP
IP
Applications
7 1680 Ports:
17. 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
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
18. 18
• 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 with
sequence numbers 0-1500 is AckNo=1501
• TCP uses the sliding window flow protocol (see CS 457) to
regulate the flow of traffic from sender to receiver
• TCP uses the following variation of sliding window:
ono NACKs (Negative ACKnowledgement)
oonly cumulative ACKs
19. 19
Header Length ( 4bits):
• Length of header in 32-bit words
• Note that TCP header has variable length (with minimum 20
bytes)
Flag bits:
• URG: Urgent pointer is valid
oIf the bit is set, the following bytes contain an urgent message in the
range:
oSeqNo <= urgent message <= SeqNo+urgent pointer
• ACK: Acknowledgement Number is valid
• PSH: PUSH Flag
oNotification from sender to the receiver that the receiver should pass all
data that it has to the application.
oNormally set by sender when the sender’s buffer is empty
20. • RST: Reset the connection
oThe flag causes the receiver to reset the connection
oReceiver of a RST terminates the connection and indicates
higher layer application about the reset
• SYN: Synchronize sequence numbers
oSent in the first packet when initiating a connection
• FIN: Sender is finished with sending
oUsed for closing a connection
oBoth sides of a connection must send a FIN
TCP Checksum:
• TCP checksum covers over both TCP header and TCP data (also
covers some parts of the IP header)
21. 21
• 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
• Urgent Pointer:
• Only valid if URG flag is set
22. • 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
23. 23
• Options:
• NOP is used to pad TCP header to multiples of 4 bytes
• Maximum Segment Size
• Window Scale Options
oIncreases the TCP window from 16 to 32 bits, I.e., the
window size is interpreted differently
oThis option can only be used in the SYN segment (first
segment) during connection establishment time
• Timestamp Option
oCan be used for roundtrip measurements
24. Connection Setup
• The client sends a synchronisation (SYN) packet
specifying
• The port number of the server
• The clients initial sequence number
• The server responds with its own SYN segment,
which specifies its initial sequence number (ISN).
The server also acknowledges the clients SYN. This
segment is called a SYN,ACK.
• The client must acknowledge the SYN from the
server by acking the server’s ISN.
• This is called a three way handshake
• Host A performs an Active Open
• Host B performs a Passive Open
• Both sides agree on initial sequence numbers
• Both sides advertise initial window sizes
• Both sides are now ready to transfer data
send
SYN
seq=x
receive SYN
segment
send SYN
seq=y,
ACK x+1
receive
SYN +ACK
segment
send ACK
y+1
receive ACK
segment
host A host B
25. Connection Closure
• It takes four segments to terminate a
connection
• Each direction of data flow is closed separately.
• It is possible for a TCP connection to be half closed
• Finish segments are issued as a result of an
application close
• ACKs of FIN segments are issued by TCP
without reference to the application
• Host A performs an active close
• Host B performs a passive close
• FIN of A is ACKed immediately by TCP
• Host B only issues its own FIN when the application
has reacted to receipt of the first FIN, by issuing a
send
FIN
seq=x
receive FIN
segment
receive
FIN +ACK
segment
send ACK
y+1
receive ACK
segment
host A host B
receive ACK
segment
send ACK
x+1
send
FIN seq=y,
ACKx+1
26. TCP State Transitions
• Each TCP connection keeps a record of its state, which allows the
connection to progress through several transitions until closure
• The state transitions facilitate connection set up and termination
• All data transfer takes place within the Established state.
27. Starting Point
Normal transitions for a server
Active open
recv: FIN
recv: ACK
send: FIN
recv: FIN
Normal transitions for a client
State
SYN_RCVD
LISTEN
ESTABLISHED
SYN_SENT
CLOSE_WAIT
LAST_ACK
FIN_WAIT_1
FIN_WAIT_2 TIME_WAIT
Key
Active Close
Passive Close
CLOSED
send: ACK
appl: passive open
Data transfer state
2MSL timeout
Name of the TCP state
appl: transition undertaken when application issues operation
recv: transition undertaken when segment received
send: what is sent for this transition
Passive Open
CLOSING
28. Starting Point
Normal transitions for a server
Active open
recv: FIN send:ACK
recv: ACK
Normal transitions for a client
State
SYN_RCVD
LISTEN
ESTABLISHED
SYN_SENT
CLOSE_WAIT
LAST_ACK
FIN_WAIT_1
FIN_WAIT_2 TIME_WAIT
Key
Active Close
Passive Close
CLOSED
Data transfer state
2MSL timeout
Name of the TCP state
appl: transition undertaken when application issues operation
recv: transition undertaken when segment received
send: what is sent for this transition
CLOSING
29. Starting Point
Normal transitions for a server
Active open
recv: FIN send:ACK
recv: ACK
send: FIN
recv: FIN
recv: ACK
Normal transitions for a client
State
SYN_RCVD
LISTEN
ESTABLISHED
SYN_SENT
CLOSE_WAIT
LAST_ACK
FIN_WAIT_1
FIN_WAIT_2 TIME_WAIT
Key
Active Close
Passive Close
CLOSED
send: ACK
appl: passive open
Data transfer state
2MSL timeout
Name of the TCP state
appl: transition undertaken when application issues operation
recv: transition undertaken when segment received
send: what is sent for this transition
Passive Open
CLOSING
30. Starting Point
Normal transitions for a server
simultaneous open
send: SYN,ACK
recv: SYN
Active open
simultaneous close
recv: FIN send:ACK
recv: FIN
send: ACK
recv: ACK
send: FIN
recv: FIN
send: FIN
recv: ACK recv: ACK
Normal transitions for a client
State
SYN_RCVD
LISTEN
ESTABLISHED
SYN_SENT
CLOSE_WAIT
LAST_ACK
CLOSINGFIN_WAIT_1
FIN_WAIT_2 TIME_WAIT
Key
Active Close
Passive Close
TCP State Transitions
CLOSED
send: ACK
appl: passive open
appl: close
Data transfer state
2MSL timeout
appl: close
or timeout
Name of the TCP state
appl: transition undertaken when application issues operation
recv: transition undertaken when segment received
send: what is sent for this transition
Passive Open