Program : B.
Tech
Subject Name: Computer Networks
Subject Code: - CS20B501
Semester: 5th
Department of Computer Science and Engineering
Subject Notes: UNIT-II
Syllabus: Data Link Layer: Need, Services Provided, Framing, Flow Control, Error control. Data Link Layer
Protocol: Elementary &Sliding Window protocol: 1-bit, Go-Back-N, Selective Repeat, Protocol
verification: Finite State Machine Models & Petri net models. ARP/RARP
DATA LINK LAYER: NEED
Data Link Layer is second layer of OSI Layered Model. This layer is one of the most complicated layers and
has complex functionalities and liabilities. Data link layer hides the details of underlying hardware and
represents itself to upper layer as the medium to communicate.
Data link layer works between two hosts which are directly connected in some sense. This direct
connection could be point to point or broadcast. Data link layer is responsible for converting data stream
to signals bit by bit and to send that over the underlying hardware.
Data link layer has two sub-
layers:
• Logical Link Control: It deals with protocols, flow-control, and error control
• Media Access Control: It deals with actual control of media
DATA LINK LAYER: SERVICE PROVIDED
• Encapsulation of network layer data packets into frames.
• Frame synchronization.
• Error Control
• Flow control, in addition to the one provided on the transport layer.
• Data packet queuing or scheduling
• Store-and-forward switching or cut-through switching
• Unacknowledged connectionless service
• Acknowledged connectionless service
• Acknowledged connection oriented service
DATA LINK LAYER: FRAMING
Since the physical layer merely accepts and transmits a stream of bits without any regard to meaning or
structure, it is up to the data link layer to create and recognize frame boundaries. This can be accomplished
by attaching special bit patterns to the beginning and end of the frame. If these bit patterns can
accidentally occur in data, special care must be taken to make sure these patterns are not incorrectly
interpreted as frame delimiters. The four framing methods that are widely used are
• Character count
• Starting and ending characters, with character stuffing
• Starting and ending flags, with bit stuffing
Page no: 1
Fig. 2.2 Data Link Layer: Framing
Character Count
This method uses a field in the header to specify the number of characters in the frame. When the data
link layer at the destination sees the character count, it knows how many characters follow, and hence
where the end of the frame is. The disadvantage is that if the count is garbled by a transmission error, the
destination will lose synchronization and will be unable to locate the start of the next frame. So, this
method is rarely used.
Character stuffing
In the second method, each frame starts with the ASCII character sequence DLE STX and ends with the
sequence DLE ETX. This method overcomes the drawbacks of the character count method. However,
character stuffing is closely associated with 8-bit characters and this is a major hurdle in transmitting
arbitrary sized characters.
Bit stuffing
The third method allows data frames to contain an arbitrary number of bits and allows character codes
with an arbitrary number of bits per character. At the start and end of each frame is a flag byte consisting
of the special bit pattern 01111110. Whenever the sender's data link layer encounters five consecutive 1s
in the data, it automatically stuffs a zero bit into the outgoing bit stream. This technique is called bit
stuffing
DATALINK LAYER: FLOW CONTROL
Flow control coordinates that amount of data that can be sent before receiving acknowledgement.
• It is one of the most important duties of the data link layer.
• Flow control tells the sender how much data to send.
• It makes the sender wait for some sort of an acknowledgment (ACK) before continuing to send more
data.
• Flow Control Techniques: Stop-and-wait, and Sliding Window
DATA LINK LAYER: ERROR CONTROL
Error control in the data link layer is based on ARQ (automatic repeat request), which is the retransmission
of data.
• The term error control refers to methods of error detection and retransmission.
• Anytime an error is detected in an exchange, specified frames are retransmitted. This process is
called ARQ.
To ensure reliable communication, there needs to exist flow control (managing the amount of data the
sender sends), and error control (that data arrives at the destination error free).
• Flow and error control needs to be done at several layers.
• For node-to-node links, flow and error control is carried out in the data-link layer.
Page no: 2
• For end-point to end-point, flow and error control is carried out in the transport layer.
There may be three types of errors:
Fig. 2.3 Single bit error
In a frame, there is only one bit, anywhere though, which is corrupt.
Fig. 2.4 burst bits error
Frame is received with more than one bit in corrupted.
DATA LINK LAYER PROTOCOL
The basic function of the layer is to transmit frames over a physical communication link. Transmission may
be half duplex or full duplex. To ensure that frames are delivered free of errors to the destination station
(IMP) a number of requirements are placed on a data link protocol. The protocol (control mechanism)
should be capable of performing:
1. The identification of a frame (i.e. recognises the first and last bits of a frame).
2. The transmission of frames of any length up to a given maximum. Any bit pattern is permitted in a
frame.
3. The detection of transmission errors.
4. The retransmission of frames which were damaged by errors.
5. The assurance that no frames were lost.
6. In a multidrop configuration some mechanism must be used for preventing conflicts caused by
simultaneous transmission by many stations.
7. The detection of failure or abnormal situations for control and monitoring purposes.
It should be noted that as far as layer 2 is concerned a host message is pure data, every single bit of which
is to be delivered to the other host. The frame header pertains to layer 2 and is never given to the host.
Page no: 3
.
Stop and Wait Protocol
Characteristics
• Used in Connection-oriented communication.
• It offers error and flow control
• It is used in Data Link and Transport Layers
• Stop and Wait ARQ mainly implements Sliding Window Protocol concept with Window Size 1
Useful Terms:
• Propagation Delay: Amount of time taken by a packet to make a physical journey from one router to
another router.
Propagation Delay = (Distance between routers) / (Velocity of propagation)
• RoundTripTime (RTT) = 2* Propagation Delay
• TimeOut (TO) = 2* RTT
• Time To Live (TTL) = 2* TimeOut. (Maximum TTL is 180 seconds)
Simple Stop and Wait
Sender:
Rule 1) Send one data packet at a time.
Rule 2) Send next packet only after receiving acknowledgement for previous.
Receiver:
Rule 1) Send acknowledgement after receiving and consuming of data packet.
Rule 2) after consuming packet acknowledgement need to be sent (Flow Control)
Fig. 2.6 Stop and Wait
Problems:
1. Lost Data
Page no: 4
Fig. 2.7 Stop and Wait- Lost Data
2. Lost Acknowledgement:
Fig. 2.8 Stop and Wait- Lost Acknowledgement
3. Delayed Acknowledgement/Data: After timeout on sender side, a long-delayed acknowledgement
might be wrongly considered as acknowledgement of some other recent packet.
Stop and Wait ARQ (Automatic Repeat Request)
Above 3 problems are resolved by Stop and Wait ARQ (Automatic Repeat Request) that does both error
control and flow control.
Fig. 2.9 Stop and Wait ARQ (Automatic Repeat Request)
1. Time Out:
Fig. 2.10 Stop and Wait ARQ-Time Out
Page no: 5
2.Sequence Number (Data)
Fig. 2.11 Stop and Wait ARQ-ACK Lost
2. Delayed Acknowledgement:
This is resolved by introducing sequence number for acknowledgement also
Working of Stop and Wait ARQ:
1) Sender A sends a data frame or packet with sequence number 0.
2) Receiver B, after receiving data frame, sends and acknowledgement with sequence number 1 (sequence
number of next expected data frame or packet)
There is only one-bit sequence number that implies that both sender and receiver have buffer for one
frame or packet only.
Page no: 6
Working of Stop and Wait ARQ:
3) Sender A sends a data frame or packet with sequence number 0.
4) Receiver B, after receiving data frame, sends and acknowledgement with sequence number 1 (sequence
number of next expected data frame or packet)
There is only one-bit sequence number that implies that both sender and receiver have buffer for one
frame or packet only.
Fig. 2.12 Working of Stop and Wait ARQ
Characteristics of Stop and Wait ARQ:
• It uses link between sender and receiver as half duplex link
• Throughput = 1 Data packet/frame per RTT
• If Bandwidth*Delay product is very high, then stop and wait protocol is not so useful. The sender has
to keep waiting for acknowledgements before sending the processed next packet.
• It is an example for “Closed Loop OR connection oriented “protocols
• It is a special category of SWP where its window size is 1
• Irrespective of number of packets sender is having stop and wait protocol requires only 2 sequences
numbers 0 and 1
The Stop and Wait ARQ solves main three problems, but may cause big performance issues as sender
always waits for acknowledgement even if it has next packet ready to send. Consider a situation where you
have a high bandwidth connection and propagation delay is also high (you are connected to some server in
some other country though a high-speed connection). To solve this problem, we can send more than one
packet at a time with a larger sequence numbers. We will be discussing these protocols in next articles.
So, Stop and Wait ARQ may work fine where propagation delay is very less for example LAN connections,
but performs badly for distant connections like satellite connection.
Page no: 7
ARP
The acronym ARP stands for Address Resolution Protocol which is one of the most important
protocols of the Data link layer in the OSI model. It is responsible to find the hardware
address of a host from a known IP address
How ARP Works?
Imagine a device that wants to communicate with others over the internet. What does ARP
do? It broadcast a packet to all the devices of the source network. The devices of the
network peel the header of the data link layer from the Protocol Data Unit (PDU) called
frame and transfer the packet to the network layer (layer 3 of OSI) where the network ID of
the packet is validated with the destination IP's network ID of the packet and if it's equal then
it responds to the source with the MAC address of the destination, else the packet reaches
the gateway of the network and broadcasts packet to the devices it is connected with and
validates their network ID. The above process continues till the second last network device in
the path reaches the destination where it gets validated and ARP, in turn, responds with the
destination MAC address.
RARP
RARP is a network protocol that allows a machine to determine its logical (IP) address using
its physical (MAC) address. Reverse Address Resolution Protocol (RARP) is a network protocol
used to map a physical machine address, such as a MAC address, to an IP address. It operates
by sending a request from a device to a RARP server, which then responds with the
corresponding IP address. This protocol is particularly relevant in the telecom and network
management industry for enabling diskless workstations and other devices to discover their
IP addresses upon booting, ensuring seamless network connectivity and management.
How does RARP Work?
Reverse ARP (RARP) is a network protocol used by a client machine in a local area network
(LAN) to obtain its Internet Protocol (IP) address from the gateway router's ARP (Address
Resolution Protocol) table. When a machine doesn't have the memory to store its IP address,
such as diskless machines or newly configured systems, it uses RARP to request an IP address.
How RARP Works:
1. Device Startup: A computer boots up with no IP address, but it knows its own MAC
address.
2. RARP Request: It broadcasts a RARP request over the network:
“This is my MAC address. Can any RARP server tell me my IP address?”
3. RARP Server Response: A RARP server on the network checks its table and replies
with the corresponding IP address.
4. IP Assigned: The device receives the response and configures its network stack with
the given IP.