transport layer protocol

   The transport layer protocol used by the TCP/IP protocol is either an improvement on one of these protocols, or a combination of them.

 

simple agreement

        Simple Protocol is a connectionless protocol that has neither flow control nor error control. We assume that the receiver is able to process any packets it receives in a timely manner. In other words, the receiver will never be overwhelmed by the influx of packets. The following figure is an outline of this protocol.

       The sender's transport layer gets a message from the application, uses it to generate a packet, and sends the packet. The receiver's transport layer receives a packet from the network layer, extracts the packet from the packet, and delivers the packet to the application layer. The sender's and receiver's transport layers provide transport services for their respective application layers.

 

FSM(Finite State Machine)

        A sender cannot send a packet until the sender's application layer has a message to send. It is also impossible for the receiver to deliver the packet to the application layer before the packet arrives. We can express these requirements with two FSMs. Each FSM has only one state, the ready state. The sender state machine remains in the ready state until another request from the application layer process. When this event occurs, the sender state machine encapsulates the message into a packet and sends the packet to the receiver state machine. The receiver state machine also always remains in the ready state until a packet arrives from the sender state machine. When this event occurs, the receiver state machine decapsulates the received packet, extracts the packet, and delivers it to the response process at the application layer. The figure below shows the FSM for this simple protocol.

        Simple Protocol is a connectionless protocol with neither flow control nor error control.

        The figure below shows an example of communication using this protocol. It's very simple. The sender sends packets one after the other without even thinking about the receiver at all.

 

 

stop waiting agreement

            The Stop-and-Wait protocol is a connection-oriented protocol that uses flow control and error control. Both sender and receiver use a sliding window of size 1 pair. The sender sends one packet at a time and waits for an acknowledgment before sending the next packet. To detect corrupted packets, we need to add a checksum to each data packet and check the packet after it reaches the receiver. If the checksum is incorrect, the packet is corrupt and the packet is silently discarded. The receiver's silence is a signal to the sender that the packet is either corrupted or lost. The sender starts a timer each time a packet is sent. If the acknowledgment arrives before the timer expires, the timer stops and the sender continues to send the next packet (if there are other packets). If the timer expires, the sender assumes that the packet is lost or damaged and retransmits the previous packet. This means that the sender needs to keep a copy of the packet until its acknowledgment arrives. The figure below shows an overview of the stop-wait protocol, note that there is only one packet and one acknowledgment in the communication channel at any one time.

       Stop-wait protocol is a connection-oriented protocol that provides flow control and error control. Flow control is achieved by forcing the sender to wait for an acknowledgment. Error control is achieved by discarding damaged packets and letting the sender retransmit after a timer expires. Acknowledged packet implementation.

 

serial number

       To prevent duplicate packets, the protocol uses sequence numbers and acknowledgment numbers. A field is added to the header of the packet to store the sequence number of the packet. The range of serial numbers needs to be carefully considered. Since we want the length of the packets to be minimized, we seek the smallest range that does not confuse the communication. Let's figure out the range of ordinal numbers required. Suppose we use x as a sequence number, then we only need to use x+1 after that, there is no need to use x+2. To illustrate this problem, we assume that the sender sends a packet with sequence number x, the following may happen three conditions:

        1. The packet arrives at the receiver perfectly well. The receiver sends an acknowledgment. This acknowledgment arrives at the sender, and the sender continues to send the next packet with sequence number x+1.

         2. The packet is damaged or never reaches the receiver. The sender retransmits the packet (sequence number x) after a timeout, and the receiver returns an acknowledgment.

         3、分组安全完好地抵达接收方,接收方发送一个确认,但是这个确认损坏或丢失了。发送方在超时后重传这个分组(序号为x)。注意此时这个分组时重复的。接收方能够识别出这种重复,因为它希望接收的分组是x+1,单实际接收到的分组却是x。

       我们看的出序号x和x+1都是必要的,因为接收方需要用他们却分情况1和情况3.但是分组没有必要使用序号x+2.在情况1中,分组可以再次使用序号x,因为分组x和x+1都已经被确认了,发送方和接收方也没有什么并不清楚的地方。在情况2和情况3中,新的分组是x+1,不是x+2,如果仅仅需要x和x+1,那么我们可以让x=0且x+1=1,也就是说该序号是0、1、0、1、0....。这被称为模2运算(通常记为mod 2)。

     

确认号

       因为序号必须既适合数据分组,又适合确认,所以我们有一下的约定:确认号总是生命了接收方准备接受的下一个分组的序号。例如:如果分组0已经安全完好地抵达了。那么接收方就发送一个确认号为1的ACK(表示下一个希望接收分组1)。如果分组1完全完好地抵达了,那么接收方就发送一个确认号为0的ACK(表示下一个希望接收分组0)。在停止等待协议中,确认号总是声明了模2运算的下一个希望接收的分组序号。

       发送方有一个控制变量,我们称之为S(sender),它指向发送窗口中唯一的空格,接收方也有一个控制变量,我们称之为R(receiver),它指向接收窗口中唯一的空格。

 

FSM

        下图描绘了停止等待协议的FSM。因为这个协议时面向连接的,所以在交换数据分组前,连接的两端都应当处于建立的状态。我们在这里所描述的状态实际上都是包含在建立的状态中的子状态。

 

 

发送方 发送方在一开始时处于准备好状态,但是它可以在准备好和阻塞这两个状态之间变换。变量S的值初始化为0.

       准备好状态 当发送方处于此状态是,它仅等待一个实践的发生。如果来自应用层的请求到达了,发送方就产生一个序号设为S的分组。这个分组的一个副本被保存起来,而这个分组被发送出去。发送方启动唯一的计时器,然后进入阻塞状态。

        阻塞状态  当发送方处于此状态时,可能会发生的事件有三个:

        1、如果一个无差错的ACK到达,且它的确认号指向下一个要发送分组,也就是说ackNo=(S+1)mod 2,那么计时器停止计时,窗口滑动使S=(S+1)mod2.最后发送方进入装备好状态。

        2、如果一个损坏的ACK到达,或者虽无差错但ackNo不等于(S+1)mod2的ACK到达,这个ACK被丢弃。

        3、如果计时器超时,发送方重新传哪个唯一待确认分组,并重启计时器。

       

接收方  接收方总是在准备好状态,变量R的初始值为0.有三个事件可能会发生:

       1、如果一个seqNo=R的无差错分组到达,那么这个分组中的报文被交付给应用层。然后欢动窗口到R=(R+1)mod 2,最后发送一个ackNo=R的ACK。

        2、如果一个seqNo不等于R的无差错分组到达,这个分组被丢弃,但是要发送ackNo=R的一个ACK。

        3、如果一个损坏的分组到达,这个分组被丢弃。

 

         下图所示为一个停止等待协议的例子。分组0被发送且确认。分组1丢失并在计时超时后重传。重传的分组1被确认且计时器停止计时。分组0被发送且被确认,但是这个确认丢失了。发送方不知道丢失的是分组还是确认,因此在计时器超时后重传分组0,重传的分组0被确认。

 

返回N协议

 

选择重传协议

 

双向协议:捎带

        数据分组仅在一个方向流动,而确认从两一个方向传过来。但是在显示生活中数据分组通常是双向流动的:从客户到服务器,并且从服务器到客户端。这就意味着确认也是需要双向流动。一种被称为捎带(piggybacking)的技术可用于提高双向协议的效率。当分组A向B携带数据的同时也能够携带返回的确认,这些确认说明了从B发来的分组的到达情况。而当分组从B向A携带数据的同时也能够携带返回的确认,这些确认又说明了从A发出来的分组的到达情况。

         下图所示为利用捎带实现双向GBN协议的概要图。客户和服务器各使用两个独立的窗口:发送窗口和接收窗口。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326413077&siteId=291194637