CN-Module 2 Notes
CN-Module 2 Notes
Module-2
Data Link Layer: Error Detection and Correction
Networks must be able to transfer data from one device to another with acceptable
accuracy. A system must guarantee that the data received are identical to the data
transmitted. Many factors can alter one or more bits of a message when it is
transmitted from one node to another. Some applications require a mechanism for
detecting and correcting errors.
Types of Errors
Whenever bits flow from one point to another, they are subject to unpredictable
changes because of interference. This interference can change the shape of the
signal.
The single-bit error means that only 1 bit of a given data unit (such as a byte,
character, or packet) is changed from 1 to 0 or from 0 to 1. The burst error
means that 2 or more bits in the data unit have changed from 1 to 0 or from 0 to
1.
A burst error is more likely to occur than a single-bit error because the duration
of the noise signal is normally longer than the duration of 1 bit, which means that
when noise affects data, it affects a set of bits. The number of bits affected
depends on the data rate and duration of noise. If we are sending data at 1 kbps,
a noise of 1/100 second can affect 10 bits
Similarly, if we are sending data at 1 Mbps, a noise of 1/100 second can affect
10000 bits
Redundancy
To detect or correct errors, we need to send some extra bits with data known as
redundant bits. These redundant bits are added by the sender and removed by
the receiver. Redundant bits allow the receiver to detect or correct corrupted bits.
Coding
Block Coding
If the following two conditions are met, the receiver can detect errors.
The sender creates code words out of datawords by using a generator. Each
codeword sent to the receiver. If the received codeword is the same as one
of the valid codewords, the word is accepted; the corresponding dataword
is extracted for use. If the received code word is not valid, it is discarded.
One of the limitation of this approach is if the codeword is corrupted during
transmission but the received word still matches a valid codeword, the error
remains undetected.
Example
Assume the sender encodes the dataword 01 as 011 and sends it to the
receiver. Consider the following cases:
Hamming Distance
The Hamming distance between two words (of the same size) is the number
of differences between the corresponding bits. Hamming distance between
two words x and y is represented as d(x, y).
Hamming distance between the received codeword and the sent codeword
is the number of bits that are corrupted during transmission.
For example, if the codeword 00000 is sent and 01101 is received, 3 bits
are in error and the Hamming distance between the two is d(00000, 01101)
= 3.
The Hamming distance can easily be found if we apply the XOR operation
(⊕) on the two words and count the number of 1s in the result. Note that
the Hamming distance is a value greater than or equal to zero.
Parity-Check Code
The minimum Hamming distance for this category is dmin = 2, which means
that the code is a single-bit error-detecting code.
The encoder uses a generator that takes a copy of a 4-bit dataword (a0,
a1, a2, and a3) and generates a parity bit r0. The dataword bits and the
parity bit create the 5-bit codeword. The parity bit that is added makes the
number of 1s in the codeword even.
r0 = a3 + a2 + a1 + a0 (modulo-2)
s0 = b3 + b2 + b1 + b0 + q0 (modulo-2)
Example:
Let us look at some transmission scenarios. Assume the sender sends the
dataword 1011. The code word created from this dataword is 10111, which
is sent to the receiver. We examine five cases:
2. One single-bit error changes a1. The received codeword is 10011. The
syndrome is 1. No dataword is created.
3. One single-bit error changes r0. The received codeword is 10110. The
syndrome is 1. No data word is created. Note that although none of the
dataword bits are corrupted, no dataword is created because the code is
not sophisticated enough to show the position of the corrupted bit.
5. Three bits—a3, a2, and a1—are changed by errors. The received codeword
is 01011. The syndrome is 1. The dataword is not created. This shows that
the simple parity check, guaranteed to detect one single error, can also find
any odd number of errors.
Cyclic codes
Cyclic codes are special linear block codes with one extra property. In a
cyclic code, if a codeword is cyclically shifted (rotated), the result is another
codeword.
• In the encoder, the dataword has k bits, the codeword has n bits.
• n – k (bits) 0s are appended to the right hand side of dataword.
• This n-bit result is fed into the generator. The generator uses a divisor
of size n − k + 1, predefined and agreed upon.
• The generator divides the augmented dataword by the divisor
(modulo-2 division).
• The quotient of the division is discarded; the remainder ( n-k bits ) is
appended to the dataword to create the codeword.
• The decoder receives the codeword. A copy of all n bits is fed to the
checker, which is a replica of the generator.
• The remainder produced by the checker is a syndrome of n – k which
is fed to the decision logic analyzer.
• Analyzer checks If the syndrome bits are all 0s, the k left most bits
of the codeword are accepted as the dataword (interpreted as no
error) else the k bits are discarded (error).
Example - Encoder
Example – Decoder
Polynomials
Degree of a Polynomial
Ex: x3 × x4 is x7
For dividing, we just subtract the power of the second term from the power
of the first.
(x5 + x3 + x2 + x)(x2 + x + 1) = x7 + x6 + x5 + x5 + x4 + x3 + x4 + x3 + x2
+ x3 + x2 + x = x7 + x6 + x3 + x
Shifting
Dataword: d(x)
Codeword: c(x)
Generator: g(x)
Syndrome: s(x)
Error: e(x)
If s(x) is not zero, then one or more bits is corrupted. However, if s(x) is
zero, either no bit is corrupted or the decoder failed to detect any errors.
The received codeword is the sum of the sent codeword and the error.
The receiver divides the received codeword by g(x) to get the syndrome.
The first term at the right-hand side of the equality has a remainder of zero.
So the syndrome is actually the remainder of the second term on the right-
hand side. If this term does not have a remainder (syndrome = 0), either
e(x) is 0 or e(x) is divisible by g(x). In a cyclic code, those e(x) errors
that are divisible by g(x) are not caught.
Single-Bit Error
If the generator has more than one term and the coefficient of x0 is 1, all
single-bit errors can be caught.
Burst error
All burst errors with L > r + 1 will be detected with probability 1 – (1/2)r.
Standard Polynomials
Reed Solomon code used today for both detection and correction.
Hardware Implementation
Checksum
assumes no error, accepts the five numbers, and discards the sum.
Otherwise, there is an error somewhere and the message is not accepted.
Checksum
Example:
• Suppose the message is a list of five 4-bit numbers(7, 11, 12, 0, 6).
The sender adds all five numbers in one’s complement to get the sum
= 6.
• The sender then complements the result to get the checksum = 9,
which is 15 − 6.
• The sender sends the five data numbers and the checksum (7, 11,
12, 0, 6, 9).
• If there is no corruption in transmission, the receiver receives (7, 11,
12, 0, 6, 9) and adds them in one’s complement to get 15.
• The sender complements 15 to get 0. This shows that data have not
been corrupted. Figure 10.16 shows the process.
Sender side
Receiver side
Internet Checksum
Performance
• For example, if the value of one word is incremented and the value
of another word is decremented by the same amount, the two errors
cannot be detected because the sum and checksum remain the same.
• If the values of several words are incremented but the sum and the
checksum do not change, the errors are not detected.
Other checksums
Fletcher Checksum
Adler Checksum
The data link control (DLC) deals with procedures for communication
between two adjacent nodes—node-to-node communication.
Data link control functions include framing and flow and error control.
Framing
• Data transmission in the physical layer means moving bits in the form
of a signal from the source to the destination.
• The data-link layer, needs to pack bits into frames, so that each frame
is distinguishable from another.
Frame Size
Character-Oriented Framing
• The universal coding systems in use today, such as Unicode, have 16-
bit and 32-bit characters that conflict with 8-bit characters, in
general, the tendency is moving toward the use of the bit-oriented
protocols.
Bit-Oriented Framing
Flow Control
• 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
Error Control
Connectionless protocol
Connection-Oriented Protocol
• After all related frames are transmitted (transfer phase), the logical
connection is terminated (teardown phase).
• 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.
Simple Protocol
Simple protocol has neither flow nor error control. It is assumed that the
receiver can immediately handle any frame it receives. the receiver is never
overwhelmed with incoming frames.
Simple protocol
• 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.
• 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.
Stop-and-Wait Protocol
Stop-and-Wait protocol
FSM
Sender States
The sender is initially in the ready state, but it can move between the ready
and blocking state.
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.
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 states
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.
Piggybacking
HDLC provides two common transfer modes that can be used in different
configurations.
Framing
Each frame in HDLC may contain up to six fields, a beginning flag field,
an address field, a control field, an information field, a frame check
sequence (FCS) field, and an ending flag field.
HDLC frames
Control field : The control field is one or two bytes used for flow and
error control.
Information field : The information field contains the user’s data from
the network layer or management information.
FCS field: The frame check sequence (FCS) is the HDLC error detection
field. It can contain either a 2- or 4-byte CRC.
• I-Frames along with user data carries flow and error control
information. I-Frame has first bit of the control field as 0.
• The next 3 bits define the sequence number of the frame N(S). We
can define a sequence number between 0 and 7.
• Supervisory frames (S Frames) are used for flow and error control
whenever piggybacking is either impossible or inappropriate.
• S-Frames will have first 2 bits as 10.
• The last 3 bits, called N(R), correspond to the acknowledgment
number (ACK) or negative acknowledgment number (NAK),
depending on the type of S-frame.
• The 2 bits called code are used to define the type of S-frame itself.
With 2 bits, we can have four types of S-frames. Depending on the
value of 2 bits we have 4 different types of S frames.
1. Receive ready (RR) - If the value of the code subfield is 00, it is
an RR S-frame. This kind of frame acknowledges the receipt of a
safe and sound frame or group of frames. In this case, the value
of the N(R) field defines the acknowledgment number.
2. Receive not ready (RNR) - If the value of the code subfield is 10,
it is an RNR S frame. This kind of frame is an RR frame with
additional functions. It acknowledges the receipt of a frame or
group of frames, and it announces that the receiver is busy and
Consider the example two exchanges using piggybacking. The first is the
case where no error has occurred; the second is the case where an error
has occurred and some frames are discarded.
Internet users who need to connect their home computers to the server
of an Internet service provider use PPP.
Framing
Flag: A PPP frame starts and ends with a 1-byte flag with the bit pattern
01111110.
Address: The address field in this protocol is a constant value and set to
11111111 (broadcast address).
Control: This field is set to the constant value 00000011 PPP does not
provide any flow control. Error control is also limited to error detection.
Protocol: The protocol field defines what is being carried in the data field:
either user data or other information. This field is by default 2 bytes long,
but the two parties can agree to use only 1 byte.
Payload field: The data field is a sequence of bytes with the default of a
maximum of 1500 bytes; but this can be changed during negotiation. The
data field is byte-stuffed if the flag byte pattern appears in this field.
Because there is no field defining the size of the data field, padding is
needed if the size is less than the maximum default value or the maximum
negotiated value.
FCS: The frame check sequence (FCS) is simply a 2-byte or 4-byte standard
CRC.
Byte Stuffing
Since PPP is a byte-oriented protocol, the flag in PPP is a byte that needs
to be escaped whenever it appears in the data section of the frame. The
escape byte is 01111101, which means that every time the flaglike pattern
appears in the data, this extra byte is stuffed to tell the receiver that the
next byte is not a flag. Obviously, the escape byte itself should be stuffed
with another escape byte.
Transition Phases
• FSM, starts with the dead state. In this state there is no active carrier
(at the physical layer) and the line is quiet.
• When one of the two nodes starts the communication, the connection
goes into the establish state.
• In this state, options are negotiated between the two parties.
• If the two parties agree that they need authentication then the
system needs to do authentication otherwise, the parties can simply
start communication. Data transfer takes place in the open state.
• The connection remains in this state until one of the endpoints wants
to terminate the connection. In this case, the system goes to the
terminate state.
Transition phases
Multiplexing
Multiplexing in PPP
There are many options that can be negotiated between the two endpoints.
Options are inserted in the information field of the configuration packets.
In this case, information field is divided into three fields: option type, option
length, and option data.
Authentication Protocols
PAP
CHAP
IPCP
One NCP protocol is the Internet Protocol Control Protocol (IPCP).
This protocol configures the link used to carry IP packets in the
Internet.
Multilink PPP
In multilink PPP, a logical PPP frame is divided into several actual PPP
frames. A segment of the logical frame is carried in the payload of an
actual PPP frame. To show that the actual PPP frame is carrying a
fragment of a logical PPP frame, the protocol field is set to (003d)16.
• When nodes or stations are connected and use a common link, called
a multipoint or broadcast link, we need a multiple-access protocol to
coordinate access to the link.
• Media Access Control (MAC) is a sublayer in the data-link layer.
Random Access
ALOHA
Pure ALOHA: Each station sends a frame whenever it has a frame to send
(multiple access). However, since there is only one channel to share, there
is the possibility of collision between frames from different stations.
There are four stations (unrealistic assumption) that contend with one
another for access to the shared channel. The figure shows that each
station sends two frames; there are a total of eight frames on the shared
medium. Some of these frames collide because multiple frames are in
contention for the shared channel. Only two frames survive: one frame
from station 1 and one frame from station 3.
A collision involves two or more stations. If all these stations try to resend
their frames after the time-out, the frames will collide again. Pure ALOHA
dictates that when the time-out period passes, each station waits a random
amount of time before resending its frame. The randomness will help avoid
more collisions. We call this time the backoff time TB.
Example:
Example:
Average frame transmission time Tfr is 200 bits/200 kbps or 1 ms. The
vulnerable time is 2 × 1 ms = 2 ms. This means no station should send
later than 1 ms before this station starts transmission and no station should
start sending during the period (1 ms) that this station is sending.
Throughput
Let us call G the average number of frames generated by the system during
one frame transmission time. Then it can be proven that the average
number of successfully transmitted frames for pure ALOHA is S = G × e−2G.
The maximum throughput Smax is 0.184, for G = 1/2.
Example
b. If the system creates 500 frames per second, or 1/2 frames per
millisecond, then G = 1/2. In this case S = G × e−2G = 0.184 (18.4
percent). This means that the throughput is 500 × 0.184 = 92 and that
only 92 frames out of 500 will probably survive. Note that this is the
maximum throughput case, percentagewise.
c. If the system creates 250 frames per second, or 1/4 frames per
millisecond, then G = 1/4. In this case S = G × e−2G = 0.152 (15.2
percent). This means that the throughput is 250 × 0.152 = 38. Only 38
frames out of 250 will probably survive.
Slotted ALOHA
In slotted ALOHA we divide the time into slots of T fr seconds and force the
station to send only at the beginning of the time slot.
Throughput
Example:
Solution This situation is similar to the previous exercise except that the
network is using slotted ALOHA instead of pure ALOHA. The frame
transmission time is 200/200 kbps or 1 ms.
CSMA
At time t1, station B senses the medium and finds it idle, so it sends a
frame. At time t2 (t2 > t1), station C senses the medium and finds it idle
because, at this time, the first bits from station B have not reached station
C. Station C also sends a frame. The two signals collide and both frames
are destroyed.
The vulnerable time for CSMA is the propagation time Tp. This is the time
needed for a signal to propagate from one end of the medium to the other.
Persistence Methods
What the channel should do if the channel is idle or busy, there are three
approaches 1-persistent method, the nonpersistent method, and the p-
persistent method.
1-Persistent
Nonpersistent
In the nonpersistent method, a station that has a frame to send senses the
line. If the line is idle, it sends immediately. If the line is not idle, it waits a
random amount of time and then senses the line again. The nonpersistent
approach reduces the chance of collision because it is unlikely that two or
more stations will wait the same amount of time and retry to send
simultaneously. However, this method reduces the efficiency of the network
because the medium remains idle when there may be stations with frames
to send.
p-Persistent
The p-persistent method is used if the channel has time slots with a slot
duration equal to or greater than the maximum propagation time. The p-
persistent approach combines the advantages of the other two strategies.
It reduces the chance of collision and improves efficiency. In this method,
after the station finds the line idle it follows these steps:
CSMA/CD
Example:
Procedure:
It is similar to the one for the ALOHA protocol, but there are differences.
Energy Level
We can say that the level of energy in a channel can have three values:
zero, normal, and abnormal. At the zero level, the channel is idle. At the
normal level, a station has successfully captured the channel and is sending
its frame. At the abnormal level, there is a collision and the level of the
energy is twice the normal level. A station that has a frame to send or is
sending a frame needs to monitor the energy level to determine if the
channel is idle, busy, or in collision mode.
Throughput
CSMA/CA
• After waiting an IFS time, if the channel is still idle, the station can
send, but it still needs to wait a time equal to the contention window.
Contention Window:
Contention window
b. After the station is found to be idle, the station waits for a period
of time called the DCF interframe space (DIFS); then the station
sends a control frame called the request to send (RTS).
2. After receiving the RTS and waiting a period of time called the short
interframe space (SIFS), the destination station sends a control frame,
called the clear to send (CTS), to the source station. This control frame
indicates that the destination station is ready to receive data.
3. The source station sends data after waiting an amount of time equal to
SIFS.
• What happens if there is a collision during the time when RTS or CTS
control frames are in transition, often called the handshaking period?
• Two or more stations may try to send RTS frames at the same time.
These control frames may collide.
• However, because there is no mechanism for collision detection, the
sender assumes there has been a collision if it has not received a CTS
frame from the receiver.
• The backoff strategy is employed, and the sender tries again.
Hidden-Station Problem
• CSMA/CA and NAV figure shows that the RTS message from B reaches
A, but not C.
• However, because both B and C are within the range of A, the CTS
message, which contains the duration of data transmission from B to
A, reaches C.
• Station C knows that some hidden station is using the channel and
refrains from transmitting until that duration is over.
CONTROLLED ACCESS
In controlled access, the stations consult one another to find which station
has the right to send. A station cannot send unless it has been authorized
by other stations.
Reservation
Polling
destination is a secondary device. The primary device controls the link; the
secondary devices follow its instructions. It is up to the primary device to
determine which device is allowed to use the channel at a given time. The
primary device, therefore, is always the initiator of a session This method
uses poll and select functions to prevent collisions. However, the drawback
is if the primary station fails, the system goes down.
Select
The select function is used whenever the primary device has something to
send. Remember that the primary controls the link. If the primary is neither
sending nor receiving data, it knows the link is available. If it has something
to send, the primary device sends it. What it does not know, however, is
whether the target device is prepared to receive. So the primary must alert
the secondary to the upcoming transmission and wait for an
acknowledgment of the secondary’s ready status. Before sending data, the
primary creates and transmits a select (SEL) frame, one field of which
includes the address of the intended secondary.
Poll
The poll function is used by the primary device to solicit transmissions from
the secondary devices. When the primary is ready to receive data, it must
ask (poll) each device if it has anything to send. When the first secondary
Token Passing
• When a station has some data to send, it waits until it receives the
token from its predecessor.
• It then holds the token and sends its data. When the station has no
more data to send, it releases the token, passing it to the next logical
station in the ring.
• When a station receives the token and has no data to send, it just
passes the data to the next station.
• For example, if a station that is holding the token fails, the token will
disappear from the network.
Logical Ring
In the physical ring topology, when a station sends the token to its
successor, the token cannot be seen by other stations; the successor is the
next one in line. This means that the token does not have to have the
address of the next successor. The problem with this topology is that if one
of the links—the medium between two adjacent stations—fails, the whole
system fails.
• The dual ring topology uses a second (auxiliary) ring which operates
in the reverse direction compared with the main ring. The second ring
is for emergencies only.
• If one of the links in the main ring fails, the system automatically
combines the two rings to form a temporary ring.
• After the failed link is restored, the auxiliary ring becomes idle again.
Note that for this topology to work, each station needs to have two
transmitter ports and two receiver ports.
In the bus ring topology, also called a token bus, the stations are connected
to a single cable called a bus. They, however, make a logical ring, because
each station knows the address of its successor (and also predecessor for
token management purposes). When a station has finished sending its
data, it releases the token and inserts the address of its successor in the
token. Only the station with the address matching the destination address
of the token gets the token to access the shared media. The Token Bus
LAN, standardized by IEEE, uses this topology.