Unit 2
Unit 2
The data link layer has a number of functions to carry out. The functions include providing a well defined
service interface to the network layer, determining how the bits of the physical layer are grouped to frames.
The design issues of the data link layer are given below
1. Services provided to the Network Layer: The function of the data link layer is to provide services to
the network layer. The principle service is transferring data from the network layer on the source
machine to the network layer in the destination machine.
The actual service offered can vary from system to system. Three reasonable possibilities that
commonly provide are :
1. Unacknowledged Connectionless Service: Source machine send independent frames to the
destination machine without expecting any reply from the destination machine.
2. Acknowledged Connectionless Service: Source machine send independent frames to the
destination machine expecting reply from the destination machine. Frames are individually
acknowledged. Here reliability is high.
3. Acknowledged Connection Oriented Services: Here Connection is first established between
source and receiver. Source machine send independent frames to the destination machine
expecting reply from the destination machine. Frames are individually acknowledged.
2. Framing
Data link layer groups bits to frames so that each frame is distinguishable from one another. Format
is as follows.
Flag Header Data Trailer Flag
Fig: Frame Format
Here sender address and destination address is also attached. The source address helps the
recipient acknowledge the receipt; the destination address defines where the packet is to go.
i) Fixed size framing: boundaries of the frame is already defined here. For eg., the size of the
frame is set as delimiter.
ii) Variable size framing:boundaries of the frame is not defined here. Two approaches used here
are
a) Character oriented protocol
variable number of data
Character oriented protocol carries data as 8-bit ASCII characters. Flags, header,trailer are also carried as 8
bits or its multiples.
Bit oriented protocols carries data as a sequence of bits. Flags, header, trailer are also carried as 8 bits or
its multiples. Flags use a special pattern like 01111110 which is used as a delimiter to define the beginning
and end of frame.
3. Flow Control: flow control is a set of procedures that tells the sender how much data it can transmit
before it must wait for an acknowledgment from the receiver. Any receiving device has a limited
speed at which it can process incoming data and a limited amount of memory in which it can store
incoming data. The receiving device must be able to inform the sending device before those limits
are reached and to request that the transmitting device send fewer frames or stop temporarily.
i) Feedback based flow control: Receiver send back the sender information regarding
permission to send more data.
ii) Rate based flow control: There is a built in mechanism that limits the rate at which the
sender may transmit data without any feedback from the receiver.
Two categories of flow control are:
a. Stop and wait
b. Sliding window
4. Error control: Error control provides error correction and detection. Some algorithms are
implemented such as checksum in error detection and correction.
PROTOCOLS
sender receiver
Packet1
ACK1
Packet2
ACK2
1. Simple
2. Error detection is easy due to its small size
Automatic Repeat Request(ARQ) is an error control method for data transmission that uses
acknowledgements and timeouts(specified period of time allowed to resend the frame
before an acknowledgment is received).
ARQ maintains reliable data transmission over an unreliable service.
Stop and wait ARQ is a form of stop and wait protocol which includes retransmission of
data in caseof lost or damaged frames.
The sending device keeps a copy of the last frame transmitted until it receives an
acknowledgement for that frame. Keeping a copy allows the sender to retransmit lost or
damaged frames until they arereceived correctly.
If an error is discovered in a data frame indicating that it has been corrupted then NAK
frame is returned which tells the sender to retransmit the last frame sent.
receiver
sender
Data1
ACK1
Data2
NAK
Data2
ACK1
Fig: Stop and wait ARQ, damaged frame
data
ACK1
wait ARQ
1. Efficiency is very less.
2. Timer set for each frame.
3. Sender window size is 1.
4. Receiver window size is 1.
Go back N ARQ
Sliding window method used here where the sender continues to send a number of frames
specified by a window size even without receiving an acknowledgement frame from the
receiver.
The sender maintains information about:
o Size of the sender window
o Last acknowledgement received
o Last frame sent
The receiver holds information about
o Receiver window size
The frames are numbered modulo-n which means they are numbered from 0 to n-1. When the
receiver sends an ACK, it includes the number of next frame it expects to receive.
Sender Sliding window can be seen as below
Frames
already send
Sender window Frames that are to be send
& ack
6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
Data 0
Data 1
Data 2
ACK
Here the frames 0,1,2 sent as a group and the acknowledgment received for the group
Sender receiver
Ack
Data 0
lost
and Data 1
time
out Data 2
ACK2
Data 0
Data 1
Data 2
Advantages of Go back N
Buffer is required
Sender needs to duplicate the last send N frames.
Retransmission of many error free packet because of resending the nth error packet
With selective repeat ARQ (also known as selective reject ARQ) the receiver sends ACK
for eachframe individually which is not cumulative ACK as used with Go Back N.
Here the sender and the receiver has window size N.
The receiver accepts frames out of order and buffers them. The sender individually
retransmits framesthat have time out.
In selective repeat ARQ only the specific damaged or lost frame is retransmitted. If a
frame iscorrupted in transit an NAK is returned and the frame is resent.
The receiving device must be able to sort the frames.
Here the data1 is damaged and the acknowledgement for the damaged frame is received and
only that data1 is resend.
Advantages of selective repeat ARQ
o Similar to Go back N ARQ. Sender only retransmits frames for which a NAK is received.
o Fewer retransmissions
Disadvantages of selective repeat ARQ
o More complex at sender and receiver side
o Each frame must be individually acknowledged
o Receiver receives frames out of sequence
Errors
When bits are transmitted over the computer network, they are subject to get corrupted due to interference
and network problems.
Types of Errors.
Single bit error − In the Multiple bits error − In the received Burst error − In the received frame,
received frame, only one bit frame, more than one bits are more than one consecutive bits are
has been corrupted, i.e. either corrupted. corrupted.
changed from 0 to 1 or from 1
to 0.
Error Control
Error detection − Error detection involves checking whether any error has occurred or not. The number of
error bits and the type of error does not matter.
Error correction − Error correction involves ascertaining the exact number of bits that has been corrupted and
the location of the corrupted bits.
There are three main techniques for detecting errors in frames: Parity Check, Checksum, and Cyclic
Redundancy Check (CRC).
Parity Check
In case of even parity: If a number of 1s is even then parity bit value is 0. If the number of 1s is odd then parity
bit value is 1.
In case of odd parity: If a number of 1s is odd then parity bit value is 0. If a number of 1s is even then parity bit
value is 1.
Checksum
Data is divided into fixed sized frames or segments.
The sender adds the segments using 1’s complement arithmetic to get the sum. It then complements the sum to
get the checksum and sends it along with the data frames.
The receiver adds the incoming segments along with the checksum using 1’s complement arithmetic to get the
sum and then complements it.
If the result is zero, the received frames are accepted; otherwise, they are discarded.
Backward Error Correction (Retransmission) − If the receiver detects an error in the incoming frame, it
requests the sender to retransmit the frame. It is a relatively simple technique. But it can be efficiently used
only where retransmitting is not expensive as in fiber optics and the time for retransmission is low relative to
the requirements of the application.
Forward Error Correction − If the receiver detects some error in the incoming frame, it executes error-
correcting code that generates the actual frame. This saves bandwidth required for retransmission. It is
inevitable in real-time systems. However, if there are too many errors, the frames need to be retransmitted .
The Media Access Control (MAC) data communication Networks protocol sub-layer, also known as the Medium
Access Control, is a sub-layer of the data link layer specified in the seven-layer OSI model.
ALOHA : ALOHA is a system for coordinating and arbitrating access to a shared communication channel. In the
ALOHA system, a node transmits whenever data is available to send. If another node transmits at the same time, a
collision occurs, and the frames that were transmitted are lost. However, a node can listen to broadcasts on the
medium, even its own, and determine whether the frames were transmitted.
Pure ALOHA
• In pure ALOHA, the stations transmit frames whenever they have data to send.
• When two or more stations transmit simultaneously, there is collision and the frames are destroyed.
In pure ALOHA, whenever any station transmits a frame, it expects the acknowledgement from the receiver.
• If acknowledgement is not received within specified time, the station assumes that the frame (or acknowledgement)
has been destroyed.
• If the frame is destroyed because of collision the station waits for a random amount of time and sends it again. This
waiting time must be random otherwise same frames will collide again and again.
• Therefore pure ALOHA dictates that when time-out period passes, each station must wait for a random amount of
time before re-sending its frame. This randomness will help avoid more collisions.
• Figure shows an example of frame collisions in pure ALOHA.
In fig there are four stations that .contended with one another for access to shared channel. All these stations are
transmitting frames. Some of these frames collide because multiple frames are in contention for the shared channel.
Only two frames, frame 1.1 and frame 2.2 survive. All other frames are destroyed.
• Whenever two frames try to occupy the channel at the same time, there will be a collision and both will be
damaged. If first bit of a new frame overlaps with just the last bit of a frame almost finished, both frames will be
totally destroyed and both will have to be retransmitted.
Slotted ALOHA
• Slotted ALOHA was invented to improve the efficiency of pure ALOHA as chances of collision in pure ALOHA
are very high.
• In slotted ALOHA, the time of the shared channel is divided into discrete intervals called slots.
• The stations can send a frame only at the beginning of the slot and only one frame is sent in each slot.
In slotted ALOHA, if any station is not able to place the frame onto the channel at the beginning of the slot i.e. it
misses the time slot then the station has to wait until the beginning of the next time slot.
• In slotted ALOHA, there is still a possibility of collision if two stations try to send at the beginning of the same time
slot as shown in fig.
• Slotted ALOHA still has an edge over pure ALOHA as chances of collision are reduced to one-half.
CSMA is a network access method used on shared network topologies such as Ethernet to control
access to the network. Devices attached to the network cable listen (carrier sense) before transmitting. CSMA
protocol was developed to overcome the problem found in ALOHA i.e. to minimize the chances of collision, so as to
improve the performance. CSMA protocol is based on the principle of ‘carrier sense’. The station senses the carrier
or channel before transmitting a frame. It means the station checks the state of channel, whether it is idle or busy.
There Are Three Different Type of CSMA Protocols
I-persistent CSMA
• In this method, station that wants to transmit data continuously senses the channel to check whether the channel is
idle or busy.
• When the station detects an idle-channel, it immediately transmits the frame with probability 1. Hence it is called I-
persistent CSMA.
• This method has the highest chance of collision because two or more stations may find channel to be idle at the
same time and transmit their frames.
• When the collision occurs, the stations wait a random amount of time and start allover again.
Drawback of I-persistent
• The propagation delay time greatly affects this protocol. Let us suppose, just after the station I begins its
transmission, station 2 also became ready to send its data and senses the channel. If the station I signal has not yet
reached station 2, station 2 will sense the channel to be idle and will begin its transmission. This will result in
collision.
Non-persistent CSMA
• In this scheme, if a station wants to transmit a frame and it finds that the channel is busy (some other station is
transmitting) then it will wait for fixed interval oftime.
• After this time, it again checks the status of the channel and if the channel is.free it will transmit.
• A station that has a frame to send senses the channel.
• If the channel is idle, it sends immediately.
• If the channel is busy, it waits a random amount of time and then senses the channel again.
• In non-persistent CSMA the station does not continuously sense the channel for the purpose of capturing it when it
detects the end of previous transmission.
Advantage of non-persistent
• It reduces the chance of collision because the stations wait a random amount of time. It is unlikely that two or more
stations will wait for same amount of time and will retransmit at the same time.
Disadvantage of non-persistent
• It reduces the efficiency of network because the channel remains idle when there may be stations with frames to
send. This is due to the fact that the stations wait a random amount of time after the collision.
p-persistent CSMA
• This method is used when channel has time slots such that the time slot duration is equal to or greater than the
maximum propagation delay time.
• With the probability q=l-p, the station then waits for the beginning of the next time slot.
• If the next slot is also idle, it either transmits or waits again with probabilities p and q.
• This process is repeated till either frame has been transmitted or another station has begun transmitting.
• In case of the transmission by another station, the station acts as though a collision has occurred and it waits a
random amount of time and starts again.
Advantage of p-persistent : • It reduces the chance of collision and improves the efficiency of the network.
Carrier Sense Multiple Access with Collision Detection (CSMA/CD)
The shared channel for communication is detected or heard, and transmissions are postponed until the
channel is clear. By detecting transmissions from other stations, the collision detection technique finds collisions.
Advantages of CSMA/CD:
Simple and widely used: CSMA/CD is a widely used protocol for Ethernet networks, and its simplicity makes it
easy to implement and use.
Fairness: In a CSMA/CD network, all devices have equal access to the transmission medium, which ensures
fairness in data transmission.
Efficiency: CSMA/CD allows for efficient use of the transmission medium by preventing unnecessary collisions
and reducing network congestion.
Disadvantages of CSMA/CD:
Limited scalability: CSMA/CD has limitations in terms of scalability, and it may not be suitable for large
networks with a high number of devices.
Vulnerability to collisions: While CSMA/CD can detect collisions, it cannot prevent them from occurring.
Collisions can lead to data corruption, retransmission delays, and reduced network performance.
Inefficient use of bandwidth: CSMA/CD uses a random backoff algorithm that can result in inefficient use of
network bandwidth if a device continually experiences collisions.
Susceptibility to security attacks: CSMA/CD does not provide any security features, and the protocol is
vulnerable to security attacks such as packet sniffing and spoofing.
Contention Window
CSMA/CA Procedure: