3.3
Elementary Data Link Protocols
To introduce the subject of
protocols, we will begin by looking at three protocols of increasing
complexity. For interested readers, a simulator for these and subsequent
protocols is available via the Web (see the preface). Before we look at the
protocols, it is useful to make explicit some of the assumptions underlying the
model of communication. To start with, we assume that in the physical layer,
data link layer, and network layer are independent processes that communicate
by passing messages back and forth. In many cases, the physical and data link
layer processes will be running on a processor inside a special network I/O
chip and the network layer code will be running on the main CPU. However, other
implementations are also possible (e.g., three processes inside a single I/O
chip; or the physical and data link layers as procedures called by the network
layer process). In any event, treating the three layers as separate processes
makes the discussion conceptually cleaner and also serves to emphasize the independence
of the layers.
Another key assumption is that
machine A wants to send a long stream of data to machine B, using a reliable,
connection-oriented service. Later, we will consider the case where B also
wants to send data to A simultaneously. A is assumed to have an infinite supply
of data ready to send and never has to wait for data to be produced. Instead,
when A's data link layer asks for data, the network layer is always able to
comply immediately. (This restriction, too, will be dropped later.)
We also assume that machines do not
crash. That is, these protocols deal with communication errors, but not the
problems caused by computers crashing and rebooting.
As far as the data link layer is
concerned, the packet passed across the interface to it from the network layer
is pure data, whose every bit is to be delivered to the destination's network
layer. The fact that the destination's network layer may interpret part of the
packet as a header is of no concern to the data link layer.
When the data link layer accepts a
packet, it encapsulates the packet in a frame by adding a data link header and
trailer to it (see Fig. 3-1). Thus, a frame consists of an embedded
packet, some control information (in the header), and a checksum (in the
trailer). The frame is then transmitted to the data link layer on the other
machine. We will assume that there exist suitable library procedures to_physical_layer
to send a frame and from_physical_layer to receive a frame. The transmitting
hardware computes and appends the checksum (thus creating the trailer), so that
the datalink layer software need not worry about it.
Initially, the receiver has nothing
to do. It just sits around waiting for something to happen. In the example
protocols of this chapter we will indicate that the data link layer is waiting
for something to happen by the procedure call wait_for_event(&event). This
procedure only returns when something has happened (e.g., a frame has arrived).
Upon return, the variable event tells what happened. The set of possible events
differs for the various protocols to be described and will be defined
separately for each protocol. Note that in a more realistic situation, the data
link layer will not sit in a tight loop waiting for an event, as we have
suggested, but will receive an interrupt, which will cause it to stop whatever
it was doing and go handle the incoming frame. Nevertheless, for simplicity we
will ignore all the details of parallel activity within the data link layer and
assume that it is dedicated full time to handling just our one channel.
When a frame arrives at the
receiver, the hardware computes the checksum. If the checksum is incorrect
(i.e., there was a transmission error), the data link layer is so informed (event
= cksum_err). If the inbound frame arrived undamaged, the data link layer is
also informed (event = frame_arrival) so that it can acquire the frame for
inspection using from_physical_layer. As soon as the receiving data link layer
has acquired an undamaged frame, it checks the control information in the
header, and if everything is all right, passes the packet portion to the
network layer. Under no circumstances is a frame header ever given to a network
layer.
There is a good reason why the
network layer must never be given any part of the frame header: to keep the
network and data link protocols completely separate. As long as the network
layer knows nothing at all about the data link protocol or the frame format,
these things can be changed without requiring changes to the network layer's software.
Providing a rigid interface between network layer and data link layer greatly
simplifies the software design because communication protocols in different
layers can evolve independently.
Figure 3-9 shows some declarations (in C) common
to many of the protocols to be discussed later. Five data structures are
defined there: boolean, seq_nr, packet, frame_kind, and frame. A boolean is an
enumerated type and can take on the values true and false. A seq_nr is a small
integer used to number the frames so that we can tell them apart. These
sequence numbers run from 0 up to and including MAX_SEQ, which is defined in
each protocol needing it. A packet is the unit of information exchanged between
the network layer and the data link layer on the same machine, or between
network layer peers. In our model it always contains MAX_PKT bytes, but more
realistically it would be of variable length.
Figure 3-9. Some definitions needed in the protocols to
follow. These definitions are located in the file protocol.h.
A frame is composed of four fields: kind,
seq, ack, and info, the first three of which contain control information and
the last of which may contain actual data to be transferred. These control
fields are collectively called the frame header.
The kind field tells whether there
are any data in the frame, because some of the protocols distinguish frames
containing only control information from those containing data as well. The seq
and ack fields are used for sequence numbers and acknowledgements,
respectively; their use will be described in more detail later. The info field
of a data frame contains a single packet; the info field of a control frame is
not used. A more realistic implementation would use a variable-length info
field, omitting it altogether for control frames.
Again, it is important to realize
the relationship between a packet and a frame. The network layer builds a
packet by taking a message from the transport layer and adding the network
layer header to it. This packet is passed to the data link layer for inclusion
in the info field of an outgoing frame. When the frame arrives at the
destination, the data link layer extracts the packet from the frame and passes
the packet to the network layer. In this manner, the network layer can act as
though machines can exchange packets directly.
A number of procedures are also
listed in Fig. 3-9. These are library routines whose
details are implementation dependent and whose inner workings will not concern
us further here. The procedure wait_for_event sits in a tight loop waiting for
something to happen, as mentioned earlier. The procedures to_network_layer and from_network_layer
are used by the data link layer to pass packets to the network layer and accept
packets from the network layer, respectively. Note that from_physical_layer and
to_physical_layer pass frames between the data link layer and physical layer.
On the other hand, the procedures to_network_layer and from_network_layer pass
packets between the data link layer and network layer. In other words, to_network_layer
and from_network_layer deal with the interface between layers 2 and 3, whereas from_physical_layer
and to_physical_layer deal with the interface between layers 1 and 2.
In most of the protocols, we assume
that the channel is unreliable and loses entire frames upon occasion. To be
able to recover from such calamities, the sending data link layer must start an
internal timer or clock whenever it sends a frame. If no reply has been
received within a certain predetermined time interval, the clock times out and
the data link layer receives an interrupt signal.
In our protocols this is handled by
allowing the procedure wait_for_event to return event = timeout. The procedures
start_timer and stop_timer turn the timer on and off, respectively. Timeouts
are possible only when the timer is running. It is explicitly permitted to call
start_timer while the timer is running; such a call simply resets the clock to
cause the next timeout after a full timer interval has elapsed (unless it is
reset or turned off in the meanwhile).
The procedures start_ack_timer and stop_ack_timer
control an auxiliary timer used to generate acknowledgements under certain
conditions.
The procedures enable_network_layer
and disable_network_layer are used in the more sophisticated protocols, where
we no longer assume that the network layer always has packets to send. When the
data link layer enables the network layer, the network layer is then permitted
to interrupt when it has a packet to be sent. We indicate this with event = network_layer_ready.
When a network layer is disabled, it may not cause such events. By being
careful about when it enables and disables its network layer, the data link
layer can prevent the network layer from swamping it with packets for which it
has no buffer space.
Frame sequence numbers are always in
the range 0 to MAX_SEQ (inclusive), where MAX_SEQ is different for the
different protocols. It is frequently necessary to advance a sequence number by
1 circularly (i.e., MAX_SEQ is followed by 0). The macro inc performs this
incrementing. It has been defined as a macro because it is used in-line within
the critical path. As we will see later, the factor limiting network
performance is often protocol processing, so defining simple operations like
this as macros does not affect the readability of the code but does improve
performance. Also, since MAX_SEQ will have different values in different
protocols, by making it a macro, it becomes possible to include all the
protocols in the same binary without conflict. This ability is useful for the
simulator.
The declarations of Fig. 3-9 are part of each of the protocols to
follow. To save space and to provide a convenient reference, they have been
extracted and listed together, but conceptually they should be merged with the
protocols themselves. In C, this merging is done by putting the definitions in
a special header file, in this case protocol.h, and using the #include facility
of the C preprocessor to include them in the protocol files.
As an initial example we will
consider a protocol that is as simple as it can be. 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 shown in Fig. 3-10.
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. No sequence numbers or acknowledgements are used here,
so MAX_SEQ is not needed. The only event type possible is frame_arrival (i.e.,
the arrival of an undamaged frame).
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 (always obliging)
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 (which is ignored anyway). 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.
Now we will drop the most
unrealistic restriction used in protocol 1: the ability of the receiving
network layer to process incoming data infinitely quickly (or equivalently, the
presence in the receiving data link layer of an infinite amount of buffer space
in which to store all incoming frames while they are waiting their respective
turns). The communication channel is still assumed to be error free however,
and the data traffic is still simplex.
The main problem we have to deal
with here is how to prevent the sender from flooding the receiver with data
faster than the latter is able to process them. In essence, if the receiver
requires a time Dt to execute from_physical_layer plus to_network_layer, the
sender must transmit at an average rate less than one frame per time Dt.
Moreover, if we assume that no automatic buffering and queueing are done within
the receiver's hardware, the sender must never transmit a new frame until the
old one has been fetched by from_physical_layer, lest the new one overwrite the
old one.
In certain restricted circumstances
(e.g., synchronous transmission and a receiving data link layer fully dedicated
to processing the one input line), it might be possible for the sender to
simply insert a delay into protocol 1 to slow it down sufficiently to keep from
swamping the receiver. However, more usually, each data link layer will have
several lines to attend to, and the time interval between a frame arriving and
its being processed may vary considerably. If the network designers can
calculate the worst-case behavior of the receiver, they can program the sender
to transmit so slowly that even if every frame suffers the maximum delay, there
will be no overruns. The trouble with this approach is that it is too
conservative. It leads to a bandwidth utilization that is far below the
optimum, unless the best and worst cases are almost the same (i.e., the
variation in the data link layer's reaction time is small).
A more general solution to this
dilemma is to have the receiver provide feedback to the sender. After having
passed a packet to its network layer, the receiver sends a little dummy frame
back to the sender which, in effect, gives the sender permission to transmit
the next frame. After having sent a frame, the sender is required by the protocol
to bide its time until the little dummy (i.e., acknowledgement) frame arrives.
Using feedback from the receiver to let the sender know when it may send more
data is an example of the flow control mentioned earlier.
Protocols in which the sender sends
one frame and then waits for an acknowledgement before proceeding are called stop-and-wait.
Figure 3-11 gives an example of a simplex
stop-and-wait protocol.
Although data traffic in this
example is simplex, going only from the sender to the receiver, frames do
travel in both directions. Consequently, the communication channel between the
two data link layers needs to be capable of bidirectional information transfer.
However, this protocol entails a strict alternation of flow: first the sender
sends a frame, then the receiver sends a frame, then the sender sends another
frame, then the receiver sends another one, and so on. A half- duplex physical
channel would suffice here.
As in protocol 1, the sender starts
out by fetching a packet from the network layer, using it to construct a frame,
and sending it on its way. But now, unlike in protocol 1, the sender must wait
until an acknowledgement frame arrives before looping back and fetching the
next packet from the network layer. The sending data link layer need not even
inspect the incoming frame: there is only one possibility. The incoming frame
is always an acknowledgement.
The only difference between receiver1
and receiver2 is that after delivering a packet to the network layer, receiver2
sends an acknowledgement frame back to the sender before entering the wait loop
again. Because only the arrival of the frame back at the sender is important,
not its contents, the receiver need not put any particular information in it.
No comments:
Post a Comment
silahkan membaca dan berkomentar