A Utopian Simplex Protocol

来源:互联网 发布:java网上订餐系统视频 编辑:程序博客网 时间:2024/06/05 04:37
We will consider a Utopian simplex data link protocol that is as simple as it can be because it does not worry about the possibility of anything going wrong. Data are transmitted in one direction only. Both the transmitting and receiving network layers are always ready. Processing time can be ignored. Infinite buffer space is available. And best of all, the communication channel between the data link layers never damages or loses frames. This thoroughly unrealistic protocol, which we will nickname "Utopia", is simply to show the basic structure on which we will build. Its implementation is shown below.
// Protocol 1 (Utopia) provides for data transmission in one direction only, from//   sender to receiver. The communication channel is assumed to be error free//   and the receiver is assumed to be able to process all the input infinitely quickly.// Consequently, the sender just sits in a loop pumping data out onto the line as//   fast as it can.typedef enum {frame_arrival} event_type;#include "protocol.h"void sender1(void){frame s;             // Buffer for an outbound frame packet buffer;                         // Buffer for an outbound packetwhile (true) {from_network_layer(&buffer);// Go get something to sends.info = buffer;         // Copy it into s for transmissionto_physical_layer(&s);     // Send it on its way}}void receiver1(void){frame r;event_type event;     // Filled in by wait, but not used herewhile (true) {wait_for_event(&event); // Only possibility is frame_arrivalfrom_physical_layer(&r); // Go get the inbound frameto_network_layer(&r.info); // Pass the data to the network layer}}
   The protocol consists of two distinct procedures, a sender and a receiver. The sender runs in the data link layer of the source machine, and the receiver runs in the data link layer of the destination machine.
      The sender is in an infinite while loop just pumping data out onto the line as fast as it can. The body of the loop consists of three actions: go fetch a packet from the network layer, construct an outbound frame using the variable s, and send the frame on its way. Only the info field of the frame is used by this protocol, because the other fields have to do with error and flow control and there are no errors or flow control restrictions here.
     The receiver is equally simple. Initially, it waits for something to happen, the only possibility being the arrival of an undamaged frame. Eventually, the frame arrives and the procedure wait_ for_event returns, with event set to frame arrival. The call to  from_ physical_layer removes the newly arrived frame from the hardware buffer and puts it in the variable r, where the receiver code can get at it. Finally, the data portion is passed on to the network layer, and the data link layer settles back to wait for the next frame, effectively suspending itself until the frame arrives.

      The utopia protocol is unrealistic because it does not handle either flow control or error correction. Its processing is close to that of an unacknowledged connectionless service that relies on higher layers to solve these problems, though even an unacknowledged connectionless service would do some error detection.
0 0
原创粉丝点击