TCP/IP
TCP/IP
 TCP/IP (Transmission Control Protocol/Internet Protocol) is the basic
communication language or protocol of the Internet.
 TCP is one of the core protocols of the Internet protocol suite (IP)
 TCP is a transport layer protocol
 TCP/IP is a two-layer program. The higher layer, Transmission Control
Protocol, manages the assembling of a message or file into smaller packets
that are transmitted over the Internet and received by a TCP layer that
reassembles the packets into the original message.
 The lower layer, Internet protocol, handles the address part of each packet
so that it gets to the right destination.
 Each gateway computer on the network checks this address to see where to
forward the message.
 Even though some packets from the same message are routed differently
than others, they'll be reassembled at the destination.
 TCP/IP uses the client/server model of communication in which a computer
user requests and is provided a service (such as sending a Web page) by
another computer in the network.
TCP/IP
 TCP/IP communication is primarily point-to-point, meaning each
communication is from one point in the network to another point or host
computer.
 TCP provides reliable, ordered and error-checked delivery of a stream
of octets (an octet is a unit of digital information in computing and
telecommunication that consists of 8 bits) between programs running on
computers connected to a LAN, intranet or the public Internet. It resides at
the transport layer
 Web browsers use TCP when they connect to servers on the World Wide
Web, and it is used to deliver email and transfer files from one location to
another.
 Applications that do not require the reliability of a TCP connection may
instead use the connectionless User Datagram Protocol (UDP), which
emphasizes low-overhead operation and reduced latency rather than error
checking and delivery validation.
TCP/IP Reference Model
 Connecting multiple networks in a flawless way
Application
Transport
Host-to-network layer
Internet
 Host has to connect to the network using some
protocol so it can send IP packets to it.
Host-to-network
The internet layer
 A packet-switching network based on a connectionless internetwork
layer
 Its job is to permit hosts to inject packets into any network and have
them travel independently to the destination.
 The internet layer defines an official packet format and protocol called
IP.
 The job of the internet layer is to deliver IP packets where they are
supposed to go. Packet routing is clearly the major issue here,
avoiding congestion
The transport layer
 It is designed to examine entries on the source and
destination hosts to carry on a conversion
 Two end-to-end protocols have been defined  TCP
(reliable, connection oriented protocol, handles flow
control) and UDP (unreliable connectionless protocol, no
sequencing and flow control, applications in which
prompt delivery is more important than accurate delivery)
The application layer
 It contains all the higher-level protocols.
 File transfer protocol  a way to move data efficiently
from one machine to another.
 Electronic mail, virtual terminal protocol etc..
Comparison between the OSI and
TCP/IP reference models
 Both are based on the concept of a stack of independent protocols
 Functionality of the layers is roughly similar
 Three concepts are central to the OSI model - Services, interfaces
and protocols
 Services - Each layer performs some services for the layer above it.
 The service definition tells what the layer does, not how entities
above it access it or how the layer works.
 If defines the layers semantics
 Interface  a layers interface tells the processes above it how to
access it.
 It specifies what the parameters are and what results to expect.
 It also says nothing about how the layer works inside
 Protocols  used in a layer are the layers own business. It can use
any protocols it wants to, as long as it gets the job done.
 It can also change them at will, without affecting software in higher
layers
 OSI model makes such a distinction between these three concepts
but, the TCP/IP model did not clearly distinguish between them.
 TCP/IP model is not much of a guide for designing new networks
using new technologies
 It is not at all general and is poorly suited to describing any protocol
stack other than TCP/IP
 Host- to network layer is not really a layer
 It does not distinguish the physical and data link layers
Application
 OSI model has proven to be exceptionally useful but
Transport
OSI protocols have not become popular
Network
 TCP/IP model is practically nonexistent
Data link
 Hybrid model  as in fig.
Physical
Exchanging messages using TCP
 The message can contain any type of data
 The system must support IP, because TCP and UDP use IP
addresses to identify a messages source and destination
 TCP and UDP are standard, well supported protocols for
computers that need to send and receive messages within local
networks or on the Internet
 Protocol
UDP TCP
datagram segment
optional required
No
yes
No
yes
No
yes
No
yes
No
yes
Yes
No
Name of unit transmitted
Source port specified to remote host
Must establish a connection before transmitting data?
Support error checking?
Support flow control?
Support handshaking?
Support sequence numbering?
Support broadcasting and multicasting?
 TCP uses a system of sequence and acknowledgement numbers
that enable the destination to acknowledge receiving specific data
bytes.
 Using sequence numbers, a destination can place received
messages in the order they were sent, even if they were received
out of order
 Sequence numbers also enable a destination to detect duplicate
received data
 TCP is called a connection-oriented protocol because processes
cant exchange data until they have exchanged communications to
establish a connection with each other.
 TCP is called a reliable protocol because the handshaking,
checksum, and sequence and acknowledgement numbers enable
the source to verify that data has arrived at its destination without
errors
 A TCP segment consists of a header optionally followed by a data
payload
 The source sends one or more segments containing data, and the
destination sends one or more segments to acknowledge receiving
the data.
 A single acknowledgement can acknowledge multiple
segments
 TCP uses port numbers to identify processes at the source
and destination
 Before two processes can send and receive data using TCP,
their computers must establish a connection by performing a
3-way handshake
 On competing the handshake, each computer has
acknowledged that the port specified in the handshake is
available to receive communications from the specified port
on the other computer
 On receiving a data over an established connection, the
destination responds by returning information about whether
the data arrived without errors or not
 To close a connection, each computer send a request to close
the connection and waits for an acknowledgment of the
request
The TCP Header
Fields
No. of
bits
Description
Source port number
16
The port that is sending the datagram
Destination port no.
16
The port, the datagram is directed to
Sequence number
32
Segment identifier
Ack. Number
32
Identifier of the last received byte
Header length
Length of TCP header in units of 32bits
Reserved
zero
Control bits
URG-urgent, ACK-ack.no. is valid, PSH-push
the data to application right away , RST-reset
the connection, SYN-synchronization is in
progress, FIN-source has no more data to send
Window
16
The no. of new bytes the source can accept
Checksum
16
Checksum value
Urgent pointer
16
sequence no. of the last byte of urgent data
options
0 or
more
Optional  can indicate the max. segment size
the source can handle
Establishing a connection
A TCP connection has two end points, one at the source and one
at the destination.
Each end point is a socket, with a port number and IP address
To complete a connection, two computers must complete a 3-way
handshake.
Each communication in the handshake contain a TCP header.
Once the connection has been established, either computer can
transmit to the other at any time
1.
The client initiates the handshake by sending a segment
containing an initial sequence number.
2.
The server waits to receive a connection request. On receiving
the segment from the client, the server responds by sending a
segment containing its own initial sequence number and an
acknowledgment no. = the received sequence no. + 1.
3.
The client responds by sending a segment whose sequence no. =
the received ack. no. and the ack. no. = received sequence no. +
1
The connection is now established
Sending and receiving data
 On receiving data, the receiver returns an
acknowledgment number equal to the sequence number
expected in the next segment
 Closing a TCP connection also requires a 3-way
handshake
 Supporting TCP in an embedded system is more
complicated than supporting UDP.
 In addition to adding and removing headers and
supporting IP, the computer must perform the 3-way
handshake to connect to a remote host, maintain
sequence and acknowledge numbers when exchanging
data, handshake when closing a connection and respond
to detected errors.
Closing a connection
 Closing a connection also requires a handshaking
 To close a connection completely, each computer sends
a segment with the FIN control bit set to 1
 To indicate that the computer has no more data to send
 Each destination must acknowledge receiving the FIN.
To send a message using TCP, a computer in
an Ethernet network must do the following:
 Establish a connection using 3-way handshake
 Use the received window size to determine how much data the
remote computer can accept
 Place the source and destination port numbers, seq., ack. no.,
header length, source window size and check sum in the
appropriate locations in the TCP header.
 Place the data to be sent in the data portion of the segment
 Place the TCP segment in the data portion of an IP datagram.
 Pass the IP datagram to the Ethernet controllers driver for sending
on the network and start a timeout timer
 Wait to receive an ack. no. that indicates that the remote computer
received the data
 If ack. doesnt arrive before the timeout, resend the segment
To receive a datagram using TCP, a computer in an Ethernet
network must do the following:
 Establish a connection using 3-way handshake
 Receive an IP datagram from the Ethernet controllers driver
 Strip the IP header from the datagram. Calculate the checksum and
compare with the received value
 If the checksum match, strip the header from the TCP segment.
Calculate the checksum and compare it to the received value
 Examine the received ack. no. to find out if the segment is
acknowledging receipt of previously sent data and if so, delete the
ack. data from the retransmission queue
 Compare the received sequence no. to the expected value. If the
numbers match, set the ack. no. to return to the sender in a TCP
segment
 Use destination port number to decide where to pass the data
In addition, at any time, either computer may request to close or reset the
connection and the other computer should ack. the request and may
request to close or reset the connection from the other end