Figure 11.8 Design of Stop-and-Wait Protocol 停等协议的设计 Sender Receiver Deliver Network Get data data Network Data link Data link Physical Receive Send Receive Send Physical frame frame frame frame Data frame ←-▣ACK frame Request from Event: network layer Repeat forever Repeat forever Algorithm for sender site Algorithm for receiver site Notification from Notification from Event: Event: physical layer physical layer 11.21
11.21 Figure 11.8 Design of Stop-and-Wait Protocol 停等协议的设计
Algorithm 11.3 Sender-site algorithm for Stop-and-Wait Protocol 停等协议的发送方的算法 1 while(true) //Repeat forever 2 canSend true //Allow the first frame to go 3 4 WaitForEvent () /Sleep until an event occurs 5 if(Event (RequestToSend)AND canSend) 6 7 GetData(); 8 MakeFrame () 9 SendFrame(); //Send the data frame 10 canSend false; //Cannot send until ACK arrives 11 12 WaitForEvent () /Sleep until an event occurs 13 if(Event (ArrivalNotification) /An ACK has arrived 14 15 ReceiveFrame(); //Receive the ACK frame 16 canSend true; 17 18 11.22
11.22 Algorithm 11.3 Sender-site algorithm for Stop-and-Wait Protocol 停等协议的发送方的算法
Algorithm 11.4 Receiver-site algorithm for Stop-and-Wait Protocol 停等协议的接收方算法 1 while(true) //Repeat forever 2 3 WaitForEvent () /Sleep until an event occurs 4 if(Event(ArrivalNotification))//Data frame arrives 5 ReceiveFrame(); ExtractData(); 6 Deliver(data); //Deliver data to network layer 9 SendFrame(); //Send an ACK frame 10 11 11.23
11.23 Algorithm 11.4 Receiver-site algorithm for Stop-and-Wait Protocol 停等协议的接收方算法
Example 11.2 Figure 11.9 shows an example of communication using this protocol.It is still very simple.The sender sends one frame and waits for feedback from the receiver.When the ACK arrives,the sender sends the next frame.Note that sending two frames in the protocol involves the sender in four events and the receiver in two events. 图11.9给出了使用停等协议的例子。协议仍然很简单。 发送方发送一帧后要等待接收方的ACK帧的反馈确认 ,才能发送下一帧。 11.24
11.24 Figure 11.9 shows an example of communication using this protocol. It is still very simple. The sender sends one frame and waits for feedback from the receiver. When the ACK arrives, the sender sends the next frame. Note that sending two frames in the protocol involves the sender in four events and the receiver in two events. 图11.9给出了使用停等协议的例子。协议仍然很简单。 发送方发送一帧后要等待接收方的ACK帧的反馈确认 ,才能发送下一帧。 Example 11.2
Figure11.9 Flow diagram for Example1l.2停等协议的帧流量图示 Sender Receiver B Request Frame Arrival ACK Arrival Request Frame Arrival ACK Arrival Time Time 11.25
11.25 Figure 11.9 Flow diagram for Example 11.2 停等协议的帧流量图示