Unit 3
Unit 3
and so on. Finally, the data-link layer at router R7 communicates with the data-link
layer at Bob’s computer. Only one data-link layer is involved at the source or the desti-
nation, but two data-link layers are involved at each router. The reason is that Alice’s
and Bob’s computers are each connected to a single network, but each router takes
input from one network and sends output to another network. Note that although
switches are also involved in the data-link-layer communication, for simplicity we have
not shown them in the figure.
Point-to-point Point-to-point
network network
The first node is the source host; the last node is the destination host. The other
four nodes are four routers. The first, the third, and the fifth links represent the three
LANs; the second and the fourth links represent the two WANs.
9.1.2 Services
The data-link layer is located between the physical and the network layers. The data-
link layer provides services to the network layer; it receives services from the physical
layer. Let us discuss services provided by the data-link layer.
The duty scope of the data-link layer is node-to-node. When a packet is travelling
in the Internet, the data-link layer of a node (host or router) is responsible for delivering
a datagram to the next node in the path. For this purpose, the data-link layer of the
sending node needs to encapsulate the datagram received from the network in a frame,
and the data-link layer of the receiving node needs to decapsulate the datagram from
the frame. In other words, the data-link layer of the source host needs only to
240 PART III DATA-LINK LAYER
encapsulate, the data-link layer of the destination host needs to decapsulate, but each
intermediate node needs to both encapsulate and decapsulate. One may ask why we
need encapsulation and decapsulation at each intermediate node. The reason is that
each link may be using a different protocol with a different frame format. Even if one
link and the next are using the same protocol, encapsulation and decapsulation are
needed because the link-layer addresses are normally different. An analogy may help in
this case. Assume a person needs to travel from her home to her friend’s home in
another city. The traveller can use three transportation tools. She can take a taxi to go to
the train station in her own city, then travel on the train from her own city to the city
where her friend lives, and finally reach her friend’s home using another taxi. Here we
have a source node, a destination node, and two intermediate nodes. The traveller needs
to get into the taxi at the source node, get out of the taxi and get into the train at the first
intermediate node (train station in the city where she lives), get out of the train and get
into another taxi at the second intermediate node (train station in the city where her
friend lives), and finally get out of the taxi when she arrives at her destination. A kind
of encapsulation occurs at the source node, encapsulation and decapsulation occur at
the intermediate nodes, and decapsulation occurs at the destination node. Our traveller
is the same, but she uses three transporting tools to reach the destination.
Figure 9.3 shows the encapsulation and decapsulation at the data-link layer. For
simplicity, we have assumed that we have only one router between the source and des-
tination. The datagram received by the data-link layer of the source host is encapsulated
in a frame. The frame is logically transported from the source host to the router. The
frame is decapsulated at the data-link layer of the router and encapsulated at another
frame. The new frame is logically transported from the router to the destination host.
Note that, although we have shown only two data-link layers at the router, the router
actually has three data-link layers because it is connected to three physical links.
Actual link
Legend 2 Data-link header
Logical link
Data link 2 Datagram Data link Data link 2 Datagram Data link
With the contents of the above figure in mind, we can list the services provided by
a data-link layer as shown below.
CHAPTER 9 INTRODUCTION TO DATA-LINK LAYER 241
Framing
Definitely, the first service provided by the data-link layer is framing. The data-link
layer at each node needs to encapsulate the datagram (packet received from the network
layer) in a frame before sending it to the next node. The node also needs to decapsulate
the datagram from the frame received on the logical channel. Although we have shown
only a header for a frame, we will see in future chapters that a frame may have both a
header and a trailer. Different data-link layers have different formats for framing.
Flow Control
Whenever we have a producer and a consumer, we need to think about flow control. If
the producer produces items that cannot be consumed, accumulation of items occurs.
The sending data-link layer at the end of a link is a producer of frames; the receiving
data-link layer at the other end of a link is a consumer. If the rate of produced frames is
higher than the rate of consumed frames, frames at the receiving end need to be buff-
ered while waiting to be consumed (processed). Definitely, we cannot have an unlim-
ited buffer size at the receiving side. We have two choices. The first choice is to let the
receiving data-link layer drop the frames if its buffer is full. The second choice is to let
the receiving data-link layer send a feedback to the sending data-link layer to ask it to
stop or slow down. Different data-link-layer protocols use different strategies for flow
control. Since flow control also occurs at the transport layer, with a higher degree of
importance, we discuss this issue in Chapter 23 when we talk about the transport layer.
Error Control
At the sending node, a frame in a data-link layer needs to be changed to bits, trans-
formed to electromagnetic signals, and transmitted through the transmission media. At
the receiving node, electromagnetic signals are received, transformed to bits, and put
together to create a frame. Since electromagnetic signals are susceptible to error, a
frame is susceptible to error. The error needs first to be detected. After detection, it
needs to be either corrected at the receiver node or discarded and retransmitted by the
sending node. Since error detection and correction is an issue in every layer (node-to-
node or host-to-host), we have dedicated all of Chapter 10 to this issue.
Congestion Control
Although a link may be congested with frames, which may result in frame loss, most
data-link-layer protocols do not directly use a congestion control to alleviate congestion,
although some wide-area networks do. In general, congestion control is considered an
issue in the network layer or the transport layer because of its end-to-end nature. We will
discuss congestion control in the network layer and the transport layer in later chapters.
have a data-link layer that uses only part of the capacity of the link. In other words, we
can have a point-to-point link or a broadcast link. In a point-to-point link, the link is
dedicated to the two devices; in a broadcast link, the link is shared between several
pairs of devices. For example, when two friends use the traditional home phones to
chat, they are using a point-to-point link; when the same two friends use their cellular
phones, they are using a broadcast link (the air is shared among many cell phone users).
Data-link layer
We discuss the DLC and MAC sublayers later, each in a separate chapter. In addi-
tion, we discuss the issue of error detection and correction, a duty of the data-link and
other layers, also in a separate chapter.
The above discussion shows that we need another addressing mechanism in a con-
nectionless internetwork: the link-layer addresses of the two nodes. A link-layer
address is sometimes called a link address, sometimes a physical address, and some-
times a MAC address. We use these terms interchangeably in this book.
Since a link is controlled at the data-link layer, the addresses need to belong to the
data-link layer. When a datagram passes from the network layer to the data-link layer,
the datagram will be encapsulated in a frame and two data-link addresses are added to
the frame header. These two addresses are changed every time the frame moves from
one link to another. Figure 9.5 demonstrates the concept in a small internet.
To another
link
N3 L3
Frame
Alice L2 L1 N1 N8 Data N2 L2 R1 N 4 L4
N1 L1
Link 1
Data
Order of addresses
N: IP address
Frame
IP addresses: source-destination
N1 N8
Legend
L: Link-layer address Link-layer address: destination-source
L4
Link 3
L5
N 8 L8 R2
N7 L7 N5 L5
Link 2
L8 L7 N1 N 8 Data
Bob
Frame
N6 L6
To another
network
In the internet in Figure 9.5, we have three links and two routers. We also have
shown only two hosts: Alice (source) and Bob (destination). For each host, we have
shown two addresses, the IP addresses (N) and the link-layer addresses (L). Note
that a router has as many pairs of addresses as the number of links the router is con-
nected to. We have shown three frames, one in each link. Each frame carries the
same datagram with the same source and destination addresses (N1 and N8), but the
link-layer addresses of the frame change from link to link. In link 1, the link-layer
addresses are L1 and L2. In link 2, they are L4 and L5. In link 3, they are L7 and L8.
Note that the IP addresses and the link-layer addresses are not in the same order. For
IP addresses, the source address comes before the destination address; for link-layer
addresses, the destination address comes before the source. The datagrams and
244 PART III DATA-LINK LAYER
frames are designed in this way, and we follow the design. We may raise several
questions:
❑ If the IP address of a router does not appear in any datagram sent from a source to a
destination, why do we need to assign IP addresses to routers? The answer is that in
some protocols a router may act as a sender or receiver of a datagram. For example,
in routing protocols we will discuss in Chapters 20 and 21, a router is a sender or a
receiver of a message. The communications in these protocols are between routers.
❑ Why do we need more than one IP address in a router, one for each interface? The
answer is that an interface is a connection of a router to a link. We will see that an
IP address defines a point in the Internet at which a device is connected. A router
with n interfaces is connected to the Internet at n points. This is the situation of a
house at the corner of a street with two gates; each gate has the address related to
the corresponding street.
❑ How are the source and destination IP addresses in a packet determined? The
answer is that the host should know its own IP address, which becomes the source
IP address in the packet. As we will discuss in Chapter 26, the application layer
uses the services of DNS to find the destination address of the packet and passes it
to the network layer to be inserted in the packet.
❑ How are the source and destination link-layer addresses determined for each link?
Again, each hop (router or host) should know its own link-layer address, as we dis-
cuss later in the chapter. The destination link-layer address is determined by using
the Address Resolution Protocol, which we discuss shortly.
❑ What is the size of link-layer addresses? The answer is that it depends on the protocol
used by the link. Although we have only one IP protocol for the whole Internet, we
may be using different data-link protocols in different links. This means that we can
define the size of the address when we discuss different link-layer protocols.
9.2.1 Three Types of addresses
Some link-layer protocols define three types of addresses: unicast, multicast, and
broadcast.
Unicast Address
Each host or each interface of a router is assigned a unicast address. Unicasting means
one-to-one communication. A frame with a unicast address destination is destined only
for one entity in the link.
Example 9.1
As we will see in Chapter 13, the unicast link-layer addresses in the most common LAN, Ether-
net, are 48 bits (six bytes) that are presented as 12 hexadecimal digits separated by colons; for
example, the following is a link-layer address of a computer.
A3:34:45:11:92:F1
Multicast Address
Some link-layer protocols define multicast addresses. Multicasting means one-to-many
communication. However, the jurisdiction is local (inside the link).
294 PART III DATA-LINK LAYER
start or end of a frame. Figure 11.1 shows the format of a frame in a character-oriented
protocol.
Character-oriented framing was popular when only text was exchanged by the
data-link layers. The flag could be selected to be any character not used for text com-
munication. Now, however, we send other types of information such as graphs, audio,
and video; any character used for the flag could also be part of the information. If this
happens, the receiver, when it encounters this pattern in the middle of the data, thinks it
has reached the end of the frame. To fix this problem, a byte-stuffing strategy was
added to character-oriented framing. In byte stuffing (or character stuffing), a special
byte is added to the data section of the frame when there is a character with the same
pattern as the flag. The data section is stuffed with an extra byte. This byte is usually
called the escape character (ESC) and has a predefined bit pattern. Whenever the
receiver encounters the ESC character, it removes it from the data section and treats the
next character as data, not as a delimiting flag. Figure 11.2 shows the situation.
Extra Extra
byte byte
Byte stuffing by the escape character allows the presence of the flag in the data
section of the frame, but it creates another problem. What happens if the text contains
one or more escape characters followed by a byte with the same pattern as the flag? The
296 PART III DATA-LINK LAYER
receiver removes the escape character, but keeps the next byte, which is incorrectly
interpreted as the end of the frame. To solve this problem, the escape characters that are
part of the text must also be marked by another escape character. In other words, if the
escape character is part of the text, an extra one is added to show that the second one is
part of the text.
Character-oriented protocols present another problem in data communications.
The universal coding systems in use today, such as Unicode, have 16-bit and 32-bit
characters that conflict with 8-bit characters. We can say that, in general, the tendency
is moving toward the bit-oriented protocols that we discuss next.
Bit-Oriented Framing
In bit-oriented framing, the data section of a frame is a sequence of bits to be interpreted by
the upper layer as text, graphic, audio, video, and so on. However, in addition to headers
(and possible trailers), we still need a delimiter to separate one frame from the other. Most
protocols use a special 8-bit pattern flag, 01111110, as the delimiter to define the begin-
ning and the end of the frame, as shown in Figure 11.3.
This flag can create the same type of problem we saw in the character-oriented
protocols. That is, if the flag pattern appears in the data, we need to somehow inform
the receiver that this is not the end of the frame. We do this by stuffing 1 single bit
(instead of 1 byte) to prevent the pattern from looking like a flag. The strategy is called
bit stuffing. In bit stuffing, if a 0 and five consecutive 1 bits are encountered, an extra
0 is added. This extra stuffed bit is eventually removed from the data by the receiver.
Note that the extra bit is added after one 0 followed by five 1s regardless of the value of
the next bit. This guarantees that the flag field sequence does not inadvertently appear
in the frame.
Bit stuffing is the process of adding one extra 0 whenever five consecutive 1s follow a 0
in the data, so that the receiver does not mistake the pattern 0111110 for a flag.
Figure 11.4 shows bit stuffing at the sender and bit removal at the receiver. Note that
even if we have a 0 after five 1s, we still stuff a 0. The 0 will be removed by the receiver.
This means that if the flaglike pattern 01111110 appears in the data, it will change
to 011111010 (stuffed) and is not mistaken for a flag by the receiver. The real flag
01111110 is not stuffed by the sender and is recognized by the receiver.
CHAPTER 11 DATA LINK CONTROL (DLC) 297
Stuffed
Frame sent
Flag Header 000111110110011111001000 Trailer Flag
Two extra
Frame received bits
Flag Header 000111110110011111001000 Trailer Flag
Unstuffed
0001111111001111101000
Data to upper layer
Flow control
298 PART III DATA-LINK LAYER
The figure shows that the data-link layer at the sending node tries to push frames
toward the data-link layer at the receiving node. If the receiving node cannot process
and deliver the packet to its network at the same rate that the frames arrive, it becomes
overwhelmed with frames. Flow control in this case can be feedback from the receiving
node to the sending node to stop or slow down pushing frames.
Buffers
Although flow control can be implemented in several ways, one of the solutions is nor-
mally to use two buffers; one at the sending data-link layer and the other at the receiv-
ing data-link layer. A buffer is a set of memory locations that can hold packets at the
sender and receiver. The flow control communication can occur by sending signals
from the consumer to the producer. When the buffer of the receiving data-link layer is
full, it informs the sending data-link layer to stop pushing frames.
Example 11.1
The above discussion requires that the consumers communicate with the producers on two
occasions: when the buffer is full and when there are vacancies. If the two parties use a buffer
with only one slot, the communication can be easier. Assume that each data-link layer uses one
single memory slot to hold a frame. When this single slot in the receiving data-link layer is
empty, it sends a note to the network layer to send the next frame.
Error Control
Since the underlying technology at the physical layer is not fully reliable, we need to
implement error control at the data-link layer to prevent the receiving node from deliver-
ing corrupted packets to its network layer. Error control at the data-link layer is normally
very simple and implemented using one of the following two methods. In both methods, a
CRC is added to the frame header by the sender and checked by the receiver.
❑ In the first method, if the frame is corrupted, it is silently discarded; if it is not cor-
rupted, the packet is delivered to the network layer. This method is used mostly in
wired LANs such as Ethernet.
❑ In the second method, if the frame is corrupted, it is silently discarded; if it is not
corrupted, an acknowledgment is sent (for the purpose of both flow and error con-
trol) to the sender.
Combination of Flow and Error Control
Flow and error control can be combined. In a simple situation, the acknowledgment that
is sent for flow control can also be used for error control to tell the sender the packet has
arrived uncorrupted. The lack of acknowledgment means that there is a problem in the
sent frame. We show this situation when we discuss some simple protocols in the next
section. A frame that carries an acknowledgment is normally called an ACK to distin-
guish it from the data frame.
Connectionless Protocol
In a connectionless protocol, frames are sent from one node to the next without any
relationship between the frames; each frame is independent. Note that the term connec-
tionless here does not mean that there is no physical connection (transmission medium)
between the nodes; it means that there is no connection between frames. The frames are
not numbered and there is no sense of ordering. Most of the data-link protocols for
LANs are connectionless protocols.
Connection-Oriented Protocol
In a connection-oriented protocol, a logical connection should first be established
between the two nodes (setup phase). After all frames that are somehow related to each
other are transmitted (transfer phase), the logical connection is terminated (teardown
phase). In this type of communication, the frames are numbered and sent in order. If
they are not received in order, the receiver needs to wait until all frames belonging to the
same set are received and then deliver them in order to the network layer. Connection-
oriented protocols are rare in wired LANs, but we can see them in some point-to-point
protocols, some wireless LANs, and some WANs.
Event 1
Note: Action 1.
The colored Action 2.
arrow shows the
starting state.
State I State II Event 2
Action 3.
Event 3
Frame
Network Network
Data-link Data-link
Logical link
Sending node Receiving node
The data-link layer at the sender gets a packet from its network layer, makes a
frame out of it, and sends the frame. The data-link layer at the receiver receives a frame
from the link, extracts the packet from the frame, and delivers the packet to its network
layer. The data-link layers of the sender and receiver provide transmission services for
their network layers.
FSMs
The sender site should not send a frame until its network layer has a message to send.
The receiver site cannot deliver a message to its network layer until a frame arrives. We
can show these requirements using two FSMs. Each FSM has only one state, the ready
state. The sending machine remains in the ready state until a request comes from the
process in the network layer. When this event occurs, the sending machine encapsulates
the message in a frame and sends it to the receiving machine. The receiving machine
remains in the ready state until a frame arrives from the sending machine. When this
event occurs, the receiving machine decapsulates the message out of the frame and
delivers it to the process at the network layer. Figure 11.8 shows the FSMs for the sim-
ple protocol. We’ll see more in Chapter 23, which uses this protocol.
CHAPTER 11 DATA LINK CONTROL (DLC) 301
Ready Ready
Start Start
Example 11.2
Figure 11.9 shows an example of communication using this protocol. It is very simple. The
sender sends frames one after another without even thinking about the receiver.
Packet
Frame
Packet
Packet
Frame
Packet
acknowledgment arrives, the sender discards the copy and sends the next frame if it is
ready. Figure 11.10 shows the outline for the Stop-and-Wait protocol. Note that only
one frame and one acknowledgment can be in the channels at any time.
Data-link Data-link
FSMs
Figure 11.11 shows the FSMs for our primitive Stop-and-Wait protocol.
Sending node
Packet came from network layer.
Make a frame, save a copy, and send the frame. Time-out.
Start the timer. Resend the saved frame.
Restart the timer.
Ready Blocking
Receiving node
❑ Ready State. When the sender is in this state, it is only waiting for a packet from
the network layer. If a packet comes from the network layer, the sender creates a
frame, saves a copy of the frame, starts the only timer and sends the frame. The
sender then moves to the blocking state.
❑ Blocking State. When the sender is in this state, three events can occur:
a. If a time-out occurs, the sender resends the saved copy of the frame and restarts
the timer.
b. If a corrupted ACK arrives, it is discarded.
c. If an error-free ACK arrives, the sender stops the timer and discards the saved
copy of the frame. It then moves to the ready state.
Receiver
The receiver is always in the ready state. Two events may occur:
a. If an error-free frame arrives, the message in the frame is delivered to the net-
work layer and an ACK is sent.
b. If a corrupted frame arrives, the frame is discarded.
Example 11.3
Figure 11.12 shows an example. The first frame is sent and acknowledged. The second frame is
sent, but lost. After time-out, it is resent. The third frame is sent and acknowledged, but the
acknowledgment is lost. The frame is resent. However, there is a problem with this scheme. The
network layer at the receiver site receives two copies of the third packet, which is not right. In the
next section, we will see how we can correct this problem using sequence numbers and acknowl-
edgment numbers.
Sequence and Acknowledgment Numbers
We saw a problem in Example 11.3 that needs to be addressed and corrected. Duplicate packets,
as much as corrupted packets, need to be avoided. As an example, assume we are ordering some
item online. If each packet defines the specification of an item to be ordered, duplicate packets
mean ordering an item more than once. To correct the problem in Example 11.3, we need to add
sequence numbers to the data frames and acknowledgment numbers to the ACK frames. How-
ever, numbering in this case is very simple. Sequence numbers are 0, 1, 0, 1, 0, 1, . . . ; the
acknowledgment numbers can also be 1, 0, 1, 0, 1, 0, … In other words, the sequence numbers
start with 0, the acknowledgment numbers start with 1. An acknowledgment number always
defines the sequence number of the next frame to receive.
Example 11.4
Figure 11.13 shows how adding sequence numbers and acknowledgment numbers can prevent
duplicates. The first frame is sent and acknowledged. The second frame is sent, but lost. After
time-out, it is resent. The third frame is sent and acknowledged, but the acknowledgment is lost.
The frame is resent.