/*Google Adsense */
Showing posts with label TCP. Show all posts
Showing posts with label TCP. Show all posts

TCP Sliding Window

A TCP sliding window provides more efficient use of network bandwidth than PAR because it enables hosts to send multiple bytes or packets before waiting for an acknowledgment.
Each TCP packet contains the starting sequence number of the data in that packet and the sequence number of the last byte (called the acknowledgment number) received from the remote peer. With this information, a sliding-window protocol is implemented. Forward and reverse sequence numbers are completely independent and each TCP peer must track both its own sequence numbering and the numbering being used by the remote peer.

Each endpoint of a TCP connection will have a buffer for storing data that is transmitted over the network before the application is ready to read the data. This lets network transfers take place while applications are busy with other processing, improving overall performance.

To avoid overflowing the buffer, TCP sets a Window Size field in each packet it transmits. This field contains the amount of data that may be transmitted into the buffer. If this number falls to zero, the remote TCP can send no more data. It must wait until buffer space becomes available and it receives a packet announcing a non-zero window size.
TCP uses a number of control flags to manage the connection. Some of these flags pertain to a single packet, such as the URG flag indicating valid data in the Urgent Pointer field, but two flags (SYN and FIN), require reliable delivery as they mark the beginning and end of the data stream. In order to insure reliable delivery of these two flags, they are assigned spots in the sequence number space. Each flag occupies a single byte.


TCP Packet Format:
  • Source port and Destination port: Identifies points at which upper layer source and destination processes receive TCP services.
  • Sequence Number: Usually specifiers the number assigned to the first byte of data in the current message. In the connection-establishment phase, this field also can be used to identify an initial sequence number to be used in an upcoming transmission.
  • Acknowledgment Number: Contains the sequence number of the next byte of data the sender of the packet expects to receive.
  • Data Offset: Indicates the number of 32-bit words in the TCP header.
  • Reserved: Remains reserved for future use.
  • Flags: Carries a variety of control information, including the SYN and ACK bits used for connection establishment, and the FIN bit used for connection termination.
  • Window: Specifies the size of the sender's receive window (that is, the buffer space available for incoming data).
  • Checksum: Indicates whether the header was damaged in transit.
  • Urgent Pointer: Points to the first urgent data byte in the packet.
  • Options: Specifies various TCP options.
  • Data: Contains upper-layer information.

In TCP, the receiver specifies the current window size in every packet. Because TCP provides a byte-stream connection, window sizes are expressed in bytes. This means that a window is the number of data bytes that the sender is allowed to send before waiting for an acknowledgment. Initial window sizes are indicated at connection setup, but might vary throughout the data transfer to provide flow control. A window size of zero, for instance, means "Send no data".

In a TCP sliding-window operation, for example, the sender might have a sequence of bytes to send (numbered 1 to 10) to a receiver who has a window size of five. The sender then would place a window around the first five bytes and transmit them together. It would then wait for an acknowledgment.

The receiver would respond with an ACK=6, indicating that it has received bytes 1 to 5 and is expecting byte 6 next. In the same packet, the receiver would indicate that its window size is 5. The sender then would move the sliding window five bytes to the right and transmit bytes 6 to 10. The receiver would respond with an ACK=11, indicating that it is expecting sequenced byte 11 next. In this packet, the receiver might indicate that its window size is 0 (because, for example, its internal buffers are full). At this point, the sender cannot send any more bytes until the receiver sends another packet with a window size greater than 0.

Positive Acknowledgment and Retransmission (PAR)

A simple transport protocol might implement a reliability-and-flow control technique where a host transmits a TCP packet to its peer, starts a timer and waits for a period of time for an acknowledgment before sending a new packet. If the acknowledgment is not received before the timer expires, the packet is assumed to have been lost and the data is retransmitted. Such a technique is called positive acknowledgment and retransmission (PAR).
However the time duration for which the source is expected to wait depends on a number of factors. Over an Ethernet, no more than a few microseconds should be needed for an acknowledgement. If the traffic is more, the time for which it has to wait should be more. All modern TCP implementations estimate this time by monitoring the normal exchange of data packets and developing an estimate of how long is "too long". This process is called Round-Trip Time (RTT) estimation. RTT estimates are one of the most important performance parameters in a TCP exchange, especially when considering the fact that on an indefinitely large transfer, all TCP implementations eventually drop packets and retransmit them, no matter how good the quality of the link. If the RTT estimate is too low, packets are retransmitted unnecessarily; if too high, the connection can sit idle while the host waits to timeout.

By assigning each packet a 32 bit sequence number, PAR enables hosts to track lost or duplicate packets caused by network delays that result in premature retransmission. The sequence numbers are sent back in the acknowledgments so that the acknowledgments can be tracked.

PAR is an inefficient use of bandwidth, however, because a host must wait for an acknowledgment before sending a new packet and only one packet can be sent at a time.

TCP Connection Establishment

To use reliable transport services, TCP hosts must establish a connection-oriented session with one another. Connection establishment is performed by using a "three-way handshake" mechanism because TCP is layered on the unreliable datagram service provided by IP, so that these control segments can by lost, duplicated or delivered out of order leading to trouble if original or retransmitted segments arrive while the connection is being established.

A three-way handshake synchronizes both ends of connection by allowing both sides to agree upon initial sequence number. This mechanism also guarantees that both sides are ready to transmit data and know that the other side is ready to transmit as well. This is necessary so that packets are not transmitted during session establishment or after session termination.

Each host randomly chooses a sequence number used to track bytes within the stream it is sending and receiving. The client initiates a connection by sending a packet with the initial sequence number (X) and SYN bit set to indicate a connection request. The server receives the SYN, records the sequence number x, and acknowledges the SYN (with an ACK = x+1). The server includes its own initial sequence number (SEQ=Y). An ACK=20 means the host has received bytes 0 through 19 and expects byte 20 next. This technique is called forward acknowledgment. The client then acknowledges all bytes the server has sent with a forward acknowledgment indicating the next byte it expects to receive (ACK=Y+1).

Transmission Control Protocol (TCP)

The TCP provides reliable transmission of data in an IP environment. TCP corresponds to the transport layer of the OSI reference model. TCP provides services like full-duplex operation, stream data transfer, reliability, efficient flow control and Network adaptation.

TCP operates in full-duplex by sending and receiving data at the same time. In stream data transfer TCP groups bytes into segments and passes them to IP for delivery. TCP offers reliability by providing connection-oriented, end-to-end reliable packet delivery through an internetwork. It does this by sequencing bytes with a forwarding acknowledgment number that indicates to the destination the netxt byte the source expects to receive. Bytes not acknowledged within a specified time period are retransmitted.

Transmission Control Protocol efficiently controls the flow, while acknowledging the source, the receiving TCP process indicates the highest sequence number it can receive without overflowing its internal buffers. TCP can adapt to network by dynamically studying the delay characteristics of a network and adjust its operation to maximize throughput without overloading the network.

TCP provides an inter process delivery system, so its needs to identify processes in the two "end systems" which it connects. Two processes can communicate by agreeing on the port numbers an abstract, that can be used for communication. Each segment contains port numbers for sending and receiving processes.

In order to set up a TCP connection, a process called server notifies the TCP software that it is waiting for connections "at" a certain port number. A process called client which is waiting for a request to be processed by the server requests the local TCP software to allocate an unused port number to connect the server and establish the connection. Once the connection is established, the two processes can communicate.