一位滑動視窗協議


滑動視窗協議是資料鏈路層協議,用於可靠且順序地交付資料幀。滑動視窗也用於傳輸控制協議。在這些協議中,傳送方有一個稱為傳送視窗的緩衝區,接收方有一個稱為接收視窗的緩衝區。

在一位元滑動視窗協議中,視窗大小為1。因此,傳送方傳送一個幀,等待其確認,然後傳送下一個幀。因此,它使用了停止等待協議的概念。此協議提供全雙工通訊。因此,確認資訊透過捎帶附加到要傳送的下一個資料幀中。

工作原理

要傳輸的資料幀還具有一個確認欄位,即 *ack* 欄位,其長度為幾位。*ack* 欄位包含最後接收到的無錯誤幀的序號。如果此序號與要傳送的幀的序號匹配,則可以推斷沒有錯誤並且幀已傳輸。否則,可以推斷幀中存在錯誤,並且重新傳輸前一個幀。

由於這是一個雙向協議,因此相同的演算法適用於兩個通訊方。

一位滑動視窗協議的演算法

begin
   frame s, r; //s and r denotes frames to be sent and received
   SeqNo = 0; // Initialise sequence number of outbound frame  
   RSeqNo = 0; // Initialise sequence number of expected frame
   while (true) //check repeatedly
   do
      Wait_For_Event(); //wait for availability of packet
      if ( Event(Request_For_Transfer) AND canSend) then
         Get_Data_From_Network_Layer();
         s = Make_Frame(SeqNo);
         Store_Copy_Frame(s);
         Start_Timer(s);
         SeqNo = SeqNo + 1;
      end if;
      Wait_For_Event(); //wait for arrival of frame
      if ( Event(Frame_Arrival) then
         r = Receive_Frame_From_Physical_Layer();
         if ( r.SeqNo = RSeqNo ) then
            Extract_Data(r);
            Deliver_Data_To_Network_Layer(r);
            Stop_Timer(r);
            RSeqNo = RSeqNo + 1;
         end if
      end if
      s.ack = r.SeqNo;
      Send_Frame_To_Physical_Layer(s);
      Start_Timer(s);
      SeqNo = SeqNo + 1;
   end while
end

示例

下圖描述了一個序列號為 0、1、2、3、0、1、2 等等的場景。它描述了幀傳輸過程中傳送站和接收站中的滑動視窗。

更新於:2019年7月30日

18K+ 次瀏覽

開啟你的職業生涯

完成課程獲得認證

開始學習
廣告