Introduction to the Transport Control Protocol (TCP) 1
来源:互联网 发布:beowulf linux 编辑:程序博客网 时间:2024/06/05 12:47
Introduction to the Transport Control Protocol (TCP)
- Origin of the TCP protocol
- The second more commonly usedtransport protocol available on the Internet isthe Transport Control Protocol (TCP)
- The TCP protocol is by far themost popular protocolused in the Internet used bynetwork application programmersto write applications (programs) that communicate with one another.
- Designers of TCP:
- TCP was developed by a team led by Vint Cerfand Bob Kahn
Read more on Vinton Cerf (and other Internet pioneers): click here
- TCP was developed by a team led by Vint Cerfand Bob Kahn
- First adoption:
- TCP was adopted in 1982 for use in the Internet.
The 1982version of TCP did not include congestion control
- TCP was adopted in 1982 for use in the Internet.
- First major improvement:
- In 1987, congestion control was added to the TCP protocol.
- The TCP protocol is documented in the Internet standard RFC 793: click here
- Services provided by the TCP protocol
- TCP provides:
- Multiplexing (same as UDP)
- Reliable delivery (TCP uses Go-back-N)
- Flow control
- Congestion control - this service was added later(in 1987) by Van Jacobson and others.
- TCP provides:
- Multiplexing
- Multiplexing in TCP is realised in thesame wayas UDP:
- User applications select and associate with a TCP port
- TCP packets contains TCP port numbers to identify packets from different user applications
- The TCP protocol also provides 216 (65536)communication portsfor use to application programs
- NOTE:
- TCP ports and UDP portsare different entitiesinside one computer
- In total, there are 65536 UDP ports and65536 TCP portsinside one computer
- Multiplexing in TCP is realised in thesame wayas UDP:
- Providing End-to-end Reliability
- Currently, TCP uses the Go-Back-Nsliding window protocol to ensure reliability.
- Recall that:
- Hop-to-hop reliability (in theDatalink layer to your neighboring nodes) doesnot guarantee end-to-end-reliability
See: click here
- Hop-to-hop reliability (in theDatalink layer to your neighboring nodes) doesnot guarantee end-to-end-reliability
- The operational environment in which theTCP layer operates ismuch more hostile than the one in whichtheDatalink layeroperates !!!
- Difference in operational environment between Transport layer and Datalink layer:
- Multiple hops between source and destinationin TCP vs. single hop in datalink layer
- Datalink layer is used betweentwo directly connected machines.
- This different result in a number of head aches for theTCP layer
- Out of order packet delivery in TCP
- Packets cannot be re-ordered whentransmitted over a single link in the datalink layer.
This is because packetstravel in the same speed over aphysical link/wire,dopacketscannot overtake each other
Result:
- The data link layer can interpret out of order reception of packets as a loss of (one or more) previous packet
(E.g., if packets 1 and 4 are received by the data link layer,it can assume thatpackets 2 and 3 are lost.
- In contrast,packets can be re-ordered duringthe transmission from source to destinationbecausedifferent packets cantakedifferent routesto the destination(due to routing table recomputation)
So, if the TCP layer receives packets 1 and 4.it CANNOTassume that packets 2 and 3 are lost.
- Packets cannot be re-ordered whentransmitted over a single link in the datalink layer.
- Varying End-to-end delay
- The sliding window protocol that ensure correctness needs to usetimeouts to recover from failures
The performance of the sliding protocoldepends heaviliyon the setting of the timeout value:
- If the time out valueis settoo large,the protocol will recover from packet losses(through retransmission)very slowly.
But if the time out valueis settoo small,the protocol will timeout prematurely andretranmit many packetunnecessaily
- The optimal setting of the timeout value depends on the end-to-end delay
The optimal value for time out is a little bit larger than twice the end-to-end delay
(because it takes approximately twice the end-to-end delay for theACK to returnto the sender)
- If the time out valueis settoo large,the protocol will recover from packet losses(through retransmission)very slowly.
- The transmission delay betweentwo neighboring nodes will not change significantly over time
Result:
- Time out values in the Datalink layer can be set very precisely
- In contrast,the end-to-end delay used by theTCP layer is highly variabledue to queueing delay in switches.
The queueing delay changes from minute to minute !!!
- Result:
- Therefore, TCP must continuously estimatethe end-to-end delay, andadjust the time out value to achievegood performance.
- The sliding window protocol that ensure correctness needs to usetimeouts to recover from failures
- Out of order packet delivery in TCP
- Multiple hops between source and destinationin TCP vs. single hop in datalink layer
- Flow control
- Flow control is controlling the rate (i.e., how fast) that thesource transmits the packets so thatthe rate of arrives of packetsdoes not overwhelm (overflow)thereceiver
Example:
- The receiver can process maximum 1000 packets per second
- If the sender transmits more than 1000 packets per second for a prolonged period of time, thereceiver's buffer will eventually overflow
- Flow control is controlling the rate (i.e., how fast) that thesource transmits the packets so thatthe rate of arrives of packetsdoes not overwhelm (overflow)thereceiver
- Congestion control
- Congestion is caused by offering more traffic (packets) than some part of the network canhandle -i.e., the demand for bandwidth in some part of the network exceeds the capacity
Example 1: a slow link
Notes:
- If the arrival rate to the red output buffer is higher than 1 Mbps for a prolonged period of time, thebuffer will overflow
Example 2: conjoint flows
Notes:
- If arrivals from three (3) different inputs are routed to thered output buffer (resulting in an arrival rate of3 Mbps) for a prolonged period of time, thebuffer will also overflow
(You can witness congestion daily on I-85 or I-75 around rush hour. Traffic congestion issimilar to network congestion:
cars arrive faster than the highway system can drain them...)
- Solving the congestion problem:
- The answer on "what to do" is easy:
- Reduce the transmission rate....
- Unfortunately, we do not knowhow to do it:
- When should be begin to reduce the transmission rate ?
- And reduce by how much ???
(If we reduced by too much, it will takemuch longer than necessary to transmit the data...)
- The answer on "what to do" is easy:
- The congestion control mechanism of TCP will be discussed much later...
- NOTE:
- In contrast, thedata link layerdoesnot need congestion control
- The reason is that the Data Link layer does not have any intermediate queuewhere packets can accumulate.
- Congestion can only occur whenpacket can ...
When a packet reaches the neighbor node of thedatalink layer, it has arrived at the destination (with respect to thedatalink layer) and thus, the packet leaves the system (with respect to the datalink layer)
So packets do not accumulate in thedatalink layer - so congestion control neccessary...
- Congestion control in TCP is still anon-going research topic !!!
- Congestion is caused by offering more traffic (packets) than some part of the network canhandle -i.e., the demand for bandwidth in some part of the network exceeds the capacity
- The Unit of data in the TCP protocol
- Fact:
- TCP is a byte oriented protocol.
I.e.:
- The unit of data transfered in TCP is one byte.
- TCP is a byte oriented protocol.
- In other words:
- Each byte must be acknowledged individually
- Example: sender transmits a TCP packet containsbyte #1 and byte #2
It will cause the receiver to send two ACKs:
- Obviously, every byte need not be acknowledged using aseparte ACK message
Recall that Go-back-N uses thecumulative ACK scheme :
- ACK(n) acknowledges all data units upto the sequence numbern
Example:
- Fact:
- How TCP interprets ACK(n)
- Previously, the interpretation ofACK(n) was:
- ACK(n) acknowledges packets withsequence numbers that are ≤ n
TCP's interpretation of ACK(n)
- ACK(n) acknowledges packets withsequence numbers that are < n !!!!
- Previously, the interpretation ofACK(n) was:
- Example acknowlegdement exchanges in TCP
- Sender and receiver parameters:
- Sender buffer is4000 bytes- andsender window sizealso equal to 4000
- Receiver buffer is4000 bytes- andreceiver window sizealso equal to4000
- Suppose currently the send and receive sequence number is1001
Graphically:
- Sender sends a TCP message that consists of400 bytes:
- SequenceNumber = 1001
- Message length = 400
Sender's window is now [1401 .. 5000]
- When the destination receives the 400 byte message:
- Receiver window slides over by an amount equal to thelength of the message (400)
(It is as if the receiver has received 400individual packets of one byte
- Receiver window slides over by an amount equal to thelength of the message (400)
- The ACK message with sequence number 1401 willcumulatively acknowledges outstanding bytes withsequence number < 1401 (or ≤ 1400)
- When the sender receives the acknowledgement,itswindow slides to 1401:
- Sender and receiver parameters:
- TCP message header format
- The format of the TCP header is as follows:
Notes:
- Source port # and destination port#:
- used for multiplexing purpose(just likeUDP)
- FLAGS: indicate a special TCP message
- SYN flag: synchronize.
SYN is set only when theTCP modulewants to establish a connection withanother TCP module.
- FIN flag: finish.
FIN is set only when theTCP layer wants to tear down (terminate) an existing connection with the other end.
(Normal exit).
- RESET flag: reset (well, what do you expect ?).
Is used by the TCP layer to reset aTCP connection.
It may tear down (terminate) apossible connection with the other end.
(Connection will be closed - abnormal exit)
- PUSH flag: flush operation
The PUSH bit is set when the user application invoked thepushoperation thatflushes the transmission buffer.
- URG flag:: indicates urgent data is sent in the TCP segment.
- ACK flag: acknowledgement.
The TCP header has two sequence number fields:
- Send sequence number
- Acknowledgement (Receive) sequence number
When this bit is set, the acknowledgement (receive) sequence number is avalidacknowledgement number
Otherwise, the receive sequence number isinvalid and must be ignored
- SYN flag: synchronize.
- SequenceNumber: send sequence number of the TCP segment.
Remember that the SequenceNumber indicates anumber of bytes (no packet number)
I.e., each data byte sent has a sequence number.
Note: as a general rule:
- Each item that require reliable transmission must be identified by its own sequence number.
Example:
- The SYN request used to establish a TCP connection and the FIN request used totear down aTCP connection, require reliable transmission
- Therefore, the SYN request and theFIN request will used one sequence number also !!!
- Each item that require reliable transmission must be identified by its own sequence number.
- Acknowlegdement Number: receive sequence number of the TCP segment.
Recall that:
- In TCP, ACK(n) acknowledges allsend sequence numbers that are < n
(Strickly not including n, that isdifferent from the traditional interpretation)
Note:the Acknowlegdement Number is only valid if the ACK flag bitis set.
- In TCP, ACK(n) acknowledges allsend sequence numbers that are < n
- Advertised WindowSize: receive window size
The Adv. window size tells thesending TCP module how many bytes areavailable in the receiver buffer
(The sender cannot send more datathan Adv. window size
More on the Advertised WindowSize field soon...
- CheckSum: checksums the TCP header & message.
- Source port # and destination port#:
- The format of the TCP header is as follows:
- Using TCP in user applications
- Definition: TCP Segment
- A TCP message is also calledTCP data segment
- A TCP data segment contains zero or more bytes
(E.g., a TCP ACK message may contains zero bytesof data)
NOTE: zero bytedata message doesnot need to be acknowledged
- Using TCP:
- A user application transmits data by using awrite operation inC/C++
(We will be learning how to write network applications in another set of lectures)
- A user application transmits data by using awrite operation inC/C++
- Effect of the write operation:
- The data written by the write operation is first stored in asend buffer
The data isnot transmittedimmediatelyto increase efficiency
- The data written by severalwrite operation can be transmitted in asingle TCP segment
- Also, the data written by a single write operation can be transmitted inmultiple TCP segments
E.g., when a large amount of data is written with asingle write operation
Graphically illustrated:
- The data written by the write operation is first stored in asend buffer
- TCP segment transmission algorithm:
- TCP maintains a MSS (Max Segment Size) variable.
When the amount of data in the send bufferis≥ MSS, TCP will transmit asegment of size MSSimmediately.
The value of MSS is usually set to themaximum transmission unit (MTU)of the data link layerminus the IP and TCP headers.
(E.g., MTU of Ethernet is 1500 bytes)
- TCP will transmits a segmentimmediately (of size less than MSS) whenthe user application issued apush request.
For example, this feature typically used by a terminal emulation program- such as Telnet - tosend user inputs when ENTER is pressed.
(In C/C++, you use the flush() system call)
- Finally, each TCP connection has a timer (set toabout 3 seconds).
When the timer expires, all data in the send bufferwill be transmitted in a TCP segment.
- TCP maintains a MSS (Max Segment Size) variable.
- The TCP module at the destination has areceive buffer.
Arriving data are stored in thereceived buffer
- The receive operation (read) canextract any amount of data fromtheTCP receive buffer with one single read operation (upto a certain maximum)
In other words:
- The read pattern is independent from how the data was sent by the sender.
- Definition: TCP Segment
- Introduction to the Transport Control Protocol (TCP) 1
- TCP-IP详解卷1-01:TCP/IP概述(Transport Control Protocol/ Internet Protocol User Datagram Protocol)
- Introduction to the Transport Device Interface[Zz]
- Introduction to the Transport Device Interface
- Introduction to the Transport Device Interface
- Introduction to Cgroups, the Linux Control Group
- Driver Development Part 5: Introduction to the Transport Device Interface
- Introduction to the TCP/IP Reference Model
- TCP: Transmission Control Protocol
- TCP, Transmission Control Protocol
- VoIP in-depth: An introduction to the SIP protocol, Part 1
- VoIP in-depth: An introduction to the SIP protocol, Part 1-2
- Stream Control Transport Protocol (SCTP) in Java
- WPF4.5 Introduction to the 24, "DataGrid Control Part 2"
- TCP/IP 详解 卷1 ch17 TCP: Transmission Control Protocol
- 17-TCP Transmission Control Protocol
- Introduction to TCP/IP
- VoIP in-depth: An introduction to the SIP protocol, Part 2
- Android中全屏或者取消标题栏
- 用CAS框架实现单点登录(tomcat7,jdk1.7)
- varchar(n),nvarchar(n) 长度、性能、及所占空间分析
- ./configure *: No such file or directory
- nyist 891 找点
- Introduction to the Transport Control Protocol (TCP) 1
- HDU 5000 Clone / 2014 ACM/ICPC Asia Regional Anshan Online
- 在U-Boot中添加命令
- j2ee规范——JDBC
- 模版的特化和偏特化
- 处理Struts2的action中对返回的json在另一端接收乱码问题
- Prefab in Prefab
- 唐山昌欣泰机械有限公司 1
- HTTP 协议详解