Professional Documents
Culture Documents
TCP
Connection-Oriented Service
During this time, a logical connection is made with the destination node
The connection is logical, since all packets are forwarded individually, just like with UDP
Acknowledgements are used to ensure packets arrive Checksums/CRCs are used to ensure data integrity
X.25 provides it at the Transport OSI layer TCP provides it at the Transport IP layer Providing connection-oriented delivery at a high level allows TCP to be applied to any network Thus the ability to use TCP/IP over Ethernet, Token Ring, etc. However, providing connection-orientation at a high level means that the network is not necessarily optimized for connection-oriented delivery For example, Ethernet is optimized for connectionless delivery
TCP
The essence of TCP is to provide an apparently continuous stream of data Thus, above the transport layer:
Data is not fragmented (into packets) Data is in order Lost packets do not occur
Thus, the transport layer (and layers below it) must handle:
Fragmentation (IP layer): only occurs when transmitting a packet whose size is larger than the MTU of the destination network Any router (connecting two different network types) could theoretically fragment packets Fragmentation can almost be considered an emergency practice (what to do when something goes wrong) Segmentation (TCP layer): Occurs for all data streams, to divide the data into packets (above TCP layer data is continuous) Only the source host will segment packets Segmentation is a normal part of TCPs job
TCP
All data sent through TCP is automatically divided into packets Each of these packets is ensured to be sent by requiring the destination acknowledge the packets when they are received The destination, knowing it will eventually receive all messages, only has to reorder those messages into an apparently continuous stream of data flow
The source sends data as a stream into the network The destination node receives data from the network in an identical form The data arrives in the same order as it was sent All data sent, arrives (in its proper position) This is known as stream orientation, a format where the data is oriented in such a way as to appear as a direct stream from source to destination In reality, however, the data is sent as packets (using IP datagrams, for example)
Data is collected from the stream (and stored into memory), until a certain amount has been obtained This data is packaged into one or more network packets (e.g. IP datagrams) and sent to the destination using connectionless delivery The destination should send an acknowledgement back to the source If this acknowledgement fails to arrive after a specified length of time, the source will retransmit the packet The destination node buffers the incoming packets into memory, where they can be read (byte by byte)
For this reason, both UDP and TCP require that the applications recognize their own data formats For example, using TCP to connect and send an E-Mail message can be achieved using the existing data format (or language) known as SMTP (Simple Mail Transfer Protocol) Using TCP to connect and request WWW pages can be achieved using HTTP (HyperText Transfer Protocol) These protocols are implemented (generated and recognized) inside the applications themselves
Since TCP is actually implemented using packets (e.g. IP datagrams), it was possible for TCP to ensure bi-directional communication across its connections
Connection Establishment
This means 3 messages are exchanged before a connection exists The first message (SYN), sent by the machine issuing the active open request (A), is a request for connection to the destination (B) The second message (SYN/ACK), both an acknowledgement of the first message as well as a request for connection to A, is sent by B The third message (ACK) is an acknowledgement to B (from A) for the second message
TCP Handshake
SYN
SYN/ACK
ACK
Transmission of data
TCP Reliability
When a packet is received by the destination, an ACK is sent back to the source When the source receives the ACK, it sends the next packet And so on, and so on,
TCP Reliability
M M M M A A A A
Network
M M M A A A
TCP Reliability
If a packet is sent, and no ACK is received within a certain time, the message will be retransmitted
It is possible that the original packet was received, but the ACK was somehow lost
TCP networks treat both situations identically The destination will receive the packet again, ignore it (it already has the data), and acknowledge it again Hopefully this time, the acknowledgement will be received
TCP Reliability
S
10 6 5 4 3 2 9 8 7 1
M M M M
Network
M M M
TCP Reliability
If each node waited for acknowledgements without transmitting data, it would involve wasteful delays between packets in a series TCP uses a scheme called the sliding window technique to solve this problem
The sliding window technique allows a transmitting node to transmit more than one packet without waiting for an ACK Nodes cannot transmit more than S packets beyond the first unacknowledged packet S is known as the window size Thus, transmitting nodes have a window of up to S packets, all of which have already been sent Some of these packets may be acknowledged At least the first packet is unacknowledged (but sent) When an ACK is received for the first packet in the window, another packet can be sent The window index can be increased by one
Passage of Time
Connection established
etc
Passage of Time
Connection established
Piggybacked ACKs
When an acknowledgement is to be sent from A to B, as well as a data packet, the ACK can be added to the packet and sent to B as one packet Essentially, only the sequencing number is required to indicate that a message has been received Sequencing numbers are discussed later
Rather than send a small packet (ACK) followed by a larger packet (data), the node sends a single larger packet (data with piggybacked acknowledgement)
TCP Layers
Application
TCP/UDP Layers
Application
TCP
UDP
These datagrams must arrive correctly Therefore, TCP streams are often created using the same information as would be used in the IP datagram header:
Ports
Therefore, ports should be used to represent which stream is which These ports are the same ones used for UDP This makes sense, considering both use IP datagrams for their implementation
Sockets
In some sense, a socket are associated with a network port on the machine
A machine (and even a single program) may have several open sockets at any time
Sockets
Datagrams from different destinations can be received on the same socket Datagrams can be sent to multiple destinations through the same socket
TCP sockets (or stream sockets) represent an active connection with the other side Both source and destination must have an active socket open for communication to occur
Stream Sockets
The side that will accept a connection requests a passive open with its operating system
This indicates that the OS should accept incoming connection requests A port is associated with the passive open, and can be used by the initiating node when requesting the connection The initiating node requests a connection with a given machine (specified by its address) at a particular port If the machine has a passive open registered at that port, the connection will be accepted, otherwise it will not
Stream Sockets
Is called a client socket Represents the act of actually connecting to a server socket
Data Corruption
TCP uses a 16 octet checksum to ensure that data has not been corrupted
If data is changed in any way, the checksum computed using the data at the destination will be different than the checksum computed on the source side (and transmitted along with the data) If checksums do not match: Data is corrupt The checksum is corrupt Both situations are treated identically in TCP, data is retransmitted
Retransmission
Similar to re-collision avoidance backoff, unacknowledged packets are sent after increasing timeouts
This prevents packets from being indefinitely lost because the timeout value is too short for extremely high network usage situations Unless a message is undeliverable, in any amount of time, the message will eventually reach its destination and be acknowledged
Connection Use
Once a connection has been made, sequence numbers are used to represent packets that make up the data stream Sequence numbers indicate the position of the data in the packet in the data stream