INF 680 Syllabus
How to Start
Schedule
Lesson 7

Read Chapter 7 in your text as well as this lesson. Then complete hw 7.

The Data Link Layer

Chapter 7 discusses the data link, layer two of the OSI model.  Layer one, which you have been studying specified the physical characteristics of a single link, such as converting bits into signals.  Layer two is responsible for the logical organization and management of communications sent over that link, such as the location, arrangement and meaning of bits in a frame.  For example, the Ethernet card in your computer must arrange bits into frames of a certain size and construct necessary header and trailer information for the frame.

There are many tasks that layer two must manage:

  • build frames
  • keep track of sent frames
  • keep track of received frames
  • notify the opposite end (layer 2) which frame is being sent and which frame in return is expected next
  • check received frames for errors
  • notify the opposite end when frames are received without error
  • request retransmission of frames that had errors
  • tell the opposite end to slow down or stop sending frames
  • tell the opposite end to begin sending frames again

These activities can be summarized into three major functions: link management, flow control and error control. 

Link management includes setting up a connection, monitoring and controlling its activity and tearing down a connection when finished.  Flow control is a way to describe techniques that prevent the transmitter from sending frames faster than the receiver can handle them.  The receiver has limited buffer space which could fill up, leaving no place to store an incoming frame.  Error control describes procedures used to handle frames that have errors, including how to check a frame for errors, what to do when errors are discovered.

Please note that error control, error detection and error correction are slightly different concepts.

    Error Detection -- finding erred frames

    Error Correction -- finding and correcting erred frames

    Error Control -- methodology of dealing with erred frames

From this point, in lesson six, we'll dig deeper into two types of flow control and three types of error control.

Flow Control

Consider a conversation with your friend.  One of you listens while the other speaks.  You might nod your head as you listen or you might interject with a "Whoa, slow down, you're talking too fast!"  This is actually flow control.  Some of us are better at it than others, but we all do it to some degree. 

You nod to indicate you understood and are ready for the next morsel of information or you tell your friend when they are going to fast.  That's flow control.

Stop and Wait Flow Control
Flow control must also be used for data communications.  The simplest form of flow control is called "Stop and Wait Flow Control."  This is very simple.  the transmitter sends one frame.  Then the transmitter stops and waits for the receiver to confirm that the frame arrived without error.  The receiver will confirm that the frame arrived by sending a message back to acknowledge the frame.  This message is referred to as an ACK (acknowledgment) or RR (receiver ready).

Once the transmitter gets the acknowledgment it can send the next frame.  In other words, frames are sent one at a time and each must be confirmed before the next one can be sent.

Take a look at the following diagram.  The transmitter is on the left (T) and the receiver (R) is on the right.  They are separated by some distance.  The vertical scale represents time, with time zero at the top.  A frame is transmitted and it takes some time to travel to the receiver.  The black arrows crossing the diagram show the leading edge and trailing edge of the frame as it travels to the receiver.

Take a look at Stop and Wait Flow Control in the next diagram.  Notice that much of the time, the receiver and the transmitter are doing nothing but waiting.

Frames are usually numbered to keep track of them.  Acknowledgments are also numbered.  Stop and Wait Flow Control need only number the frames as frame 0 and frame 1.  The acknowledgments are numbered ACK0 and ACK1.

Look how much time the transmitter is doing nothing in the above diagram.  When a frame is small, much of the time is spent waiting for it to travel across the network and for the ACK to return. 

One solution to this problem of poor efficiency is to send larger frames.  When frames are larger, more time is spent sending data.  Larger frames are more efficient as long as there are few errors.  If there is an error the entire frame has to be resent.  The larger the frame the more likely there will be an error in it, so there is a point where no benefits are found by increasing the frame size.  When there are frequent errors very small frames might be appropriate.

Another solution to the poor efficiency is another form of flow control called Sliding Window Flow Control.

Sliding Window Flow Control
With a relatively error free link, sliding window flow control is more efficient than stop and wait.  The improvement is that the transmitter is granted permission to send more than one frame in a row before it has to stop and wait for an acknowledgment. 

Let's say that the transmitter and the receiver agree that seven frames can be sent at a time.  The transmitter starts out with permission to send seven frames.  We'll define the number of frames that can be sent as the "window".  Frames 1 through 7 may be sent immediately.

If all seven frames are sent, the transmitter has to stop and wait.  The receiver may send an ACK when it is ready to receive another 7 frames.  The ACK will set the transmitters window back to seven sendable frames.  In the case above the receiver has sent an ACK5.  This message means that frames 1 through 4 were received correctly and that the receiver is "expecting frame 5 next." 

When the transmitter gets ACK5 is knows that beginning with frame 5 is may send seven frames.  Some of those frames may have already been sent, though, so the transmitter sends the remaining frames in the window.

The transmitter has to keep track of which frames in the window have been sent and which can be sent.  It has to know which frames have been acknowledged as well.  After sending 7 frames in the above diagram, the transmitter has to stop and wait.  Once ACK5 arrives it marks frames 1 to 4 as acknowledged and "slides" its seven-frame window down to include frames 5 to 11.  Having already sent frames 5, 6, and 7, the transmitter now sends 8 through 11.  Then the transmitter waits again.

The receiver may choose not to acknowledge frames so that the transmitter will exhaust its supply of sendable frames and stop transmitting.  This is how the receiver controls the pace of incoming frames.  When the receiver is ready to receive another 7 frames, it can send an ACK.

If there are no problems with the incoming pace, the receiver sends frequent ACKs so that the transmitter never exhausts its window.  This is where the efficiency is accomplished.  The transmitter can send continuously when the receiver processes frames more quickly than they arrive because the receivers buffer space never fills up.

Computers work in binary.  So, to keep count of frames they will use several bits in the control field of the frame for the send number.  They will also have a few bits for the receive number.  Since both sides will have information to send, full duplex transmission, both sides will have a window, send numbers and receiver numbers. 

If three bits are reserved for the send number, then ...

    L = 2n
    L = 23
    L = 8

... the window size is 8.  For most systems, when the last frame is sent, the number rolls over and starts from zero again.  Remember that counting in binary starts will zero, not one.  Not all sequence numbers roll over to zero upon reaching the window size number.  The window size can be smaller, even much smaller than the frame sequence numbers.

This roll over could cause a problem.  What if the transmitter receives an ACK3, then sends frames 3, 4, 5, 6, 7, 0, 1, and 2, and then receives an ACK3?  Is this a repeat ACK3 or a new ACK 3.  For this reason the transmitter will always set its window to one less than the maximum.  That way the problem cannot occur.  This means that:

  • 3 bit sequence fields permit a window size of 7, not 8
  • 8 bit sequence fields permit a window size of 255, not 256

In practice the most common window sizes at layer 2, the data link layer, are 7 and 127.  However, on low-error links of great distance it is beneficial to increase the window size.

In summary:

  • The window slides when acknowledgments are received
  • Only frames inside the window may be sent.
  • Sent frames remain in the window until an acknowledgment moves the window.
  • window size = 2n -1

Error Control
So, the receiver can control the pace of incoming frames by carefully timing acknowledgments.  But, what happens if a frame is received in error?  Of course some set of procedures must be defined so that errors can be dealt with. 

Three types of error control are discussed in your text.  All are collectively called automatic repeat request, or ARQ.  The three types of error control are:

  • Stop and Wait ARQ
  • Go Back N ARQ
  • Selective Reject ARQ

Please don't confuse Stop and Wait Flow Control with Stop and Wait ARQ.  These are different concepts that are part of a stop and wait transmission protocol.

Stop and Wait ARQ
In a stop and wait system, if a frame arrives and an error check indicates that somewhere in the frame there is an error, the frame is discarded and a message is sent to notify the transmitter.  The message sent is a negative acknowledgment, also called a reject message (NAK or REJ). 

What happens if a frame, an ACK or a NAK are lost in transit?  This could be a problem, so when a frame is sent, the transmitter starts a timer.  If the timer counts down to zero before an ACK or NAK is received the transmitter resends the frame.

This condition is known as a "time out".  Note the following:

  • If a frame is lost, after the transmitter times out, the frame is resent and the receiver accepts it without no knowledge of the lost frame.
  • If a NAK is lost, the transmitter times out and resends the frames.  the receiver accepts the  retransmitted frame as if the NAK had been received normally.  Ah, there is no requirement to send a NAK.  The transmitter will resend the frame anyway.  Sending the NAK forces the transmitter to resend immediately, rather than waiting for a time out to occur.
  • If an ACK is lost, the transmitter times out and resends the frame.  The receiver already has this frame, so it discards the duplicate and resends the ACK.

Go-Back-N ARQ
The Go-Back-N ARQ error control method is used in combination with sliding window flow control.  When the receiver finds a frame in error, it tells the transmitter to go back, resend that frame and all succeeding frames.  After the erred frame, some succeeding frames will arrive.  The receiver discards these knowing that the erred frame will arrive and the succeeding frames will also follow.

This feature guarantees that frames are received in order, but it also means that some good frames may have to be resent.

In the above graphic, note how the transmitter begins by resending the frame that was in error and then continues by sending succeeding frames until its window is exhausted..

Selective Reject ARQ
For a system with ample memory space, Selective Reject Request ARQ may provide improved performance when compared to Go-Back-N ARQ.  This error control scheme allows the receiver to selectively reject frames. 

The receiver, upon finding and erred frame, will request that frame be resent and only that frame is resent.  The receiver has to keep track of what frames are coming in and what sequence they belong in.  Reordering the frames may be required.  The receiver cannot deliver frame contents to layer three until the frames have been put in order and no frames are missing in the sequence.

The transmitter also has to keep careful track of which frames have been sent, which have been acknowledged and which are available to be sent.  Selective Reject ARQ works in combination with sliding window flow control.

Selective Reject ARQ is not common at the data link layer.  It requires much more processing and buffer space to implement. The marginal improvement in capacity is not easy to justify in the hardware used at the data link layer. We will see Selective Reject ARQ later when we study TCP, however.

Summary

Flow Control

advantages

disadvantages

Stop and Wait

Very simple
low buffer requirement
low processor burden

very inefficient

Sliding Window

very efficient for links with low error rates

not efficient on error prone links

     

Error Control

advantages

disadvantages

Stop and Wait ARQ

easy to implement
low processor burden
low buffer requirement

doesn't allow sliding window flow control

Go-Back-N ARQ

easy to implement
permits use of sliding window flow control

may have to retransmit good frames

Selective Reject ARQ

permits sliding window flow control, only retransmit lost or erred frames

requires more powerful processing and more buffer space

Detecting Errors
Before leaving the topic of error control it will be useful to mention how errors are detected.  So far, we have seen one method of detecting errors, the use of parity bits.  Parity bits are used with asynchronous ASCII character transmission for example.  These bits indicate if an odd number of bits are in error.  They do not, however, tell us which bits are in error.  In this sense, we can detect but not correct the errors.  If we knew which bit was in error we could change it and that would fix the error.

Another method of error detection, called a cyclic redundancy check (CRC) uses mathematics to tackle the problem of error detection (not error correction).  CRC error checking is quite powerful and easily implemented.  You will not be tested on your modulo-2 mathematics, so relax.  That is beyond the scope of our studies.  Just consider the following:

  • The data bits in a frame are divided by a fixed binary number that both the transmitter and the receiver know.
  • The remainder of this division is tacked on to the binary data and sent in the frame to the other end.
  • the receiver performs a division of the combined data with its attached remainder. 
  • This division should result in no remainder at all, indicating that no bits are in error.

Advantages

  • detects any number of errors
  • probability of an undetected error is extremely low (but not zero)
  • only requires a small addition of bits to the frame

Disadvantages

  • does not correct errors
  • requires more powerful processing than a parity check

The preceding discussion centered around general techniques for operating a single link between a transmitter and a receiver.  Now let's look at a very popular protocol, often used on network routers, such as Cisco routers where it is the default serial line protocol

High-level Data Link Control
HDLC is a protocol that allows for the exchange of frames at the Data Link layer using sliding window flow control and go-back-n error control.  HDLC standards establish the format of the frames and the link management, including flow and error control methods.  Link setup and tear down procedures are also specified in the standard.

Take a look at this HDLC frame.  The first bit to be send on the medium would be on the left so we'll call that the start of the frame.  The frame is divided into six fields.

 

The flag field identifies the beginning of the frame.  For HDLC it is always 01111110.  An identical flag field marks the end of the frame.  Following that is an address field which can be used if more than two stations are using the same medium.  The control field is where we put those sequence numbers for go-back-n.  ACK and REJ messages also go in the control field.  The data field is where layer three information is encapsulated.  This is sometimes called the "payload."  The frame check sequence is a CRC error check which contains that binary division remainder mentioned earlier in this lesson.

Flag Field
The flag field is always 01111110.  HDLC is asynchronous so an unknown period of time passes before the next frame arrives.  When it does, some method of synchronization is required.  The first 8 bits of the frame will always follow the 01111110 pattern and this allows the receiver to synchronize its timing clock.  By using the same flag at the end of the frame, the receiver knows where the end of the frame is.  This means that each frame can be a different size. 

However, because the end of the frame is not fixed, the receiver will be searching for the 01111110 pattern, which might by coincidence occur naturally somewhere earlier in the frame.  That would be bad because the receiver would assume it had reached the end of the frame, back up to locate the frame check sequence bits and perform an error check that would surely indicate an erred frame.

To avoid this all fields except the two flag fields are "bit stuffed."  Bit stuffing is also called zero-bit insertion.  This is easy to do and it prevents any false flags from appearing to chop of the end of the frame.

Zero-bit insertion is just that, for all fields between the flag fields, the transmitter inserts an additional zero after every string of five 1s in a row.  The receiver watches for strings of five 1s in a row and removes one zero that occurs after those five ones.  If six ones and a zero are encountered that indicates the final flag.

Example: Use zero-bit insertion on the following bit stream, 0101111111111010.

    0 1 0 1 1 1 1 1 1 1 1 1 1 0 1 0      original
                   ^         ^
                   0         0           inserted bits

    0 1 0 1 1 1 1 1 0 1 1 1 1 1 0 0 1 0  final bit stream

    Boundaries between the fields are not a concern.  Bits are counted consecutively.

Address Field
HDLC supports more than just two stations on the physical media.  In order to do so each station needs a unique address, which usually has 8 bits in the address field.  Actually, if the field begins with a 1 it means the following seven bits are the address.  If the field begins with a 0, then the address field is expanded to 16 bits, 15 of which could be used for station addresses.  An address has to be unique, of course, except that a broadcast address, all ones, can be used to send a message that will go to all stations.

Using an 8-bit address field there are only 7 bits left for addresses.  That would permit ...

    L = 2n
    L = 27
    L = 127

... 127 unique stations.

If the first bit is is a zero, you'd have a 16-bit field.  It is left to the student as an exercise to determine the number of stations addresses would be possible.  More commonly however, HDLC only links from one station to another.  So, there is usually no need for fancy addressing schemes. 

 

Control field
The control field is where the sequence numbers (in binary) are located.  For a full-duplex channel, both end stations are sending and receiving messages.  Both will have a window to keep track of, and both will have to send acknowledgments.  The control field allows one end to send a frame with its associated sequence number in the control field and an acknowledgment number in the control field as well.

The control field is 8 bits, usually.  The transmitter and receiver agree on the size when the establish a connection.  The first bit defines what kind of frame this is.  Usually a 0 is located in the first bit and it means that this is an information frame carrying layer three data.  A 1 indicates that the frame is just used for acknowledgments and that no information is included.  The information field is actually omitted. 

The remaining seven bits are divided up between the send sequence number, a poll/final bit and the acknowledgment sequence number.  That means that the send number is a 3-bit binary number.  This permits a window size of 7 frames (23 - 1 = 7 frames).

Data Field
Layer three data is encapsulated by the HDLC header and trailer.  The data field is where the layer three information resides.  This field can vary in length, say up to about 1,500 bytes.  Partial bytes are not allowed, so the last byte might have zeros included to pad out the final octet of the info field.

Frame Check Sequence
This is a CRC frame check that is almost always 16 bits long.  A very robust error checking mechanism can operate using only 16 bits.  This is where the CRC remainder is added to the information field.

Conclusion
Many protocols are actually based on HDLC.  They have similar frame structure and operation.  For example, Frame Relay links at the data link layer use a modified version of HDLC to manage the exchange of data. 

Complete hw7 and hand it in according to the schedule.

[INF 680 Syllabus] [How to Start] [Schedule]

Used with permission of the Author; Copyright (C) Kevin A. Shaffer 1998 - 2018, all rights reserved.