UNIT2 Notes
UNIT2 Notes
KMIT/CSE/III-I 1
FUNCTIONS OF DATA LINK LAYER
The functionality and sub functionalities of Data Link Layer are given below:
Data Link
Noiseless Noisy
KMIT/CSE/III-I 2
Figure shows the byte stuffing and Unstuffing:
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.
KMIT/CSE/III-I 3
Note: the extra bit is added after one 0 followed by five 1s regardless of the value of the next
bit. (i.e.) when 01111100 is a part of the data, then also we have to add “0” after five 1‟s .
Hence the data will be 011111000
Cyclic Codes
In a cyclic code, if a codeword is cyclically shifted (rotated), the result is another codeword.
Example: If 1011000 is a codeword and we cyclically left-shift, then 0110001 is also a
codeword.
Dataword 1011000
Codeword 0110001
In the above table the dataword size is 4 and codeword size is 7. Codeword can be obtained
by applying the CRC procedure as we mentioned above. Now let us check for the dataword
1001, and how we get codeword 1001110.
Encoder
The encoder takes the dataword and augments it with (n – k) number of 0‟s. It then divides
the augmented dataword by the divisor. Let us take the divisor 1011.The value 1011 will
agreed by both sender and receiver.
Note: We use XOR operation in the above division.
As in decimal division, the process is done step by step.
In each step, a copy of the divisor is XORed with the 4 bits of the dividend.
The result of the XOR operation (remainder) is 3 bits is used for the next step after 1 extra
bit is pulled down to make it 4 bits long.
If the leftmost bit of the dividend is 0, the step cannot use the regular divisor; we need to
use an all-0‟s divisor.
When there are no bits left to pull down, we have a result.
The 3-bit remainder forms the check bits (r2r1 r0). They are appended to the dataword to
create the codeword.
KMIT/CSE/III-I 5
Decoder
The codeword can change during transmission.
The decoder does the same division process as the encoder.
The remainder of the division is the syndrome.
If the syndrome is all 0‟s, there is no error; the dataword is separated from the received
codeword and accepted. Otherwise, everything is discarded.
The below figure shows two cases:
The left-hand figure shows the value of syndrome when no error has occurred; the
syndrome is 000.
The right-hand part of the figure shows the case in which there is one single error. The
syndrome is not all 0‟s (it is 011).
KMIT/CSE/III-I 6
4. In detail, explain the various ALOHA protocols.
ALOHA
ALOHA was developed at the University of Hawaii in early 1970. It was designed for a
Wireless radio LAN, but it can be used on any shared medium. Due to shared medium there
are potential collisions in this arrangement.
There are two types of methods in ALOHA
i. Pure ALOHA
ii. Slotted ALOHA
Pure ALOHA
The original ALOHA or Pure ALOHA is a simple protocol.
The idea is that each station sends a frame whenever it has a frame to send, there is only one
channel to share, and there is the possibility of collision between frames from different
stations.
l In the above figure, there are four stations each sending two frames and shares the same
channel. Some of these frames collide because multiple frames are in contention for the
shared channel.
l By observing the above figure only 2 frames frame 1.1 and frame 3.2 can be delivered at
receiver, and the remaining frames collide with each other and they are lost or discarded
at the receiver side.
l The pure ALOHA protocol relies on Acknowledgments (ACK) from the receiver. When a
station sends a frame, it expects the receiver to send an acknowledgment.
l If the acknowledgment does not arrive after a time-out period, the station assumes that the
frame (or the acknowledgment) has been destroyed and resends the frame.
l 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.
KMIT/CSE/III-I 7
l 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; this time is called the Back-Off Time TB.
l Pure ALOHA has a second method to prevent congesting the channel with retransmitted
frames. After a maximum number of retransmission attempts Kmax a station must give up
and try later.
The procedure for pure ALOHA is given in the figure:
l The time-out period is equal to the maximum possible round-trip propagation delay,
which is twice the amount of time required to send a frame between the two most widely
separated stations (2 x Tp).
l The back-off time TB is a random value that normally depends on K (the number of
attempted unsuccessful transmissions).
l For each retransmission, a multiplier in the range 0 to 2K - 1 is randomly chosen and
multiplied by Tp (maximum propagation time) or Tfr (Frame transmission time or the
average time required to send out a frame) to find TB.
l Note that in this procedure, the range of the random numbers increases after each
collision. The value of Kmax is usually chosen as 15.
Vulnerable time
Vulnerable time is the length of time, in which there is a possibility of collision.
Let us assume that the stations send fixed-length frames with each frame taking Tfr’s to send.
Station A sends a frame at time t.
Now station B has already sent a frame between t - Tfr and t.
This leads to a collision between the frames from station A and station B.
The end of B's frame collides with the beginning of A's frame.
KMIT/CSE/III-I 8
Suppose that station C sends a frame between t and t + Tfr .
Here, there is a collision between frames from station A and station C. The beginning of C's
frame collides with the end of A's frame.
The vulnerable time, during which a collision may occur in pure ALOHA, is 2 times the
frame transmission time.
Pure ALOHA vulnerable time = 2 x Tfr
Throughput
l The throughput for pure ALOHA is S = G x e-2G .
l The maximum throughput Smax = 0.184 when G = (½).
l (i.e.) one frame is generated during two frame transmission times, then 18.4 percent of
these frames reach their destination successfully.
Slotted ALOHA
Pure ALOHA has a vulnerable time of 2 x Tfr . This is so because there is no rule that
defines when the station can send.
A station may send soon after another station has started or soon before another
station has finished.
Slotted ALOHA was invented to improve the efficiency of pure ALOHA.
In slotted ALOHA we divide the time into slots of Tfr‟s and force the station to send
only at the beginning of the time slot.
A station is allowed to send only at the beginning of the synchronized time slot, if a
station misses this moment, it must wait until the beginning of the next time slot.
This means that the station which started at the beginning of this slot has already
finished sending its frame.
There is still the possibility of collision if two stations try to send at the beginning of
the same time slot.
i.e. the vulnerable time for slotted ALOHA is one-half that of pure ALOHA.
Slotted ALOHA vulnerable time = Tfr.
KMIT/CSE/III-I 9
Below figure shows an example of frame collisions in slotted ALOHA.
Throughput
l The throughput for slotted ALOHA is S =: G x e-G.
l The maximum throughput Smax == 0.368 when G =1.
l If a frame is generated during one frame transmission time, then 36.8 percent of these
frames reach their destination successfully.
In this protocol
l Sender can send several frames before receiving acknowledgments.
l Sender keep a copy of these frames until the acknowledgments arrive.
Design of Go-Back-N ARQ
The idea is similar to Stop-and-Wait ARQ, multiple frames can be in transit in the forward
direction, and multiple acknowledgments in the reverse direction.
The difference is that the send window allows us to have as many frames in transition as
there are slots in the send window.
KMIT/CSE/III-I 10
This protocol uses the following concepts:
1. Sequence Numbers
2. Sliding Window
3. Timers
4. Acknowledgement
5. Retransmission (Resending a Frame)
Sequence Numbers
l It is a number given to each frame included in the header.
l The header of the frame allows m bits for the sequence number, the sequence numbers
range from 0 to 2m-1.
KMIT/CSE/III-I 11
l The sequence numbers are repeated after the number 2m-1 (i.e) the sequence numbers are
modulo-2m
Example:
If m=4 , the sequence numbers are 0,1,2,3,4,5………14,15,0,1,2,3,4,5,6,…………………..
Sliding Window
Sliding Window is an abstract concept that defines the sender and receiver needs to deal with
only part of the possible sequence numbers.
There are 2 types of windows are used:
i. Send Window
ii. Receive Window
The range that is the concern of sender is called the send sliding window or Send Window
The range that is the concern of receiver is called receive sliding window or receive window.
Send Window
l The send window is an imaginary box covering the sequence numbers of the data frames
which can be in transit.
l In each window position, some of these sequence numbers define the frames that have
been sent; others define those that can be sent.
l The maximum size of the send window is 2m – 1.
Example: Let us take m=4. Size of window=15.
Consider the below figure:
The window at any time divides the possible sequence numbers into four regions.
1. The first region (the left side of the window) defines the sequence numbers belonging to
frames that are already acknowledged. The sender don‟t need to keep copies of the
frames.
2. The second region defines the range of sequence numbers belonging to the frames that are
sent and have an unknown status. The sender needs to wait to find out if these frames
have been received or were lost. These frames are called outstanding frames.
KMIT/CSE/III-I 12
3. The third range defines the range of sequence numbers for frames that can be sent. The
corresponding data packets have not yet been received from the network layer.
4. The fourth region defines sequence numbers that cannot be used until the window slides.
The window uses three variables define its size and location at any time.
i. Sf defines the sequence number of the first (oldest) outstanding frame.
ii. Sn holds the sequence number that will be assigned to the next frame to be sent.
iii. Ssize defines the size of the window, which is fixed in our protocol.
The acknowledgments in this protocol are cumulative, meaning that more than one frame can
be acknowledged by an ACK frame.
In the above figure frames 0, 1, and 2 are acknowledged, so the window has slid to the right
three slots.
Receive Window
l The receive window makes sure that the correct data frames are received and that the
correct acknowledgments are sent.
l The size of the receive window is always 1.
l The receiver is always looking for the arrival of a specific frame.
l Any frame arriving out of order is discarded and needs to be resent.
There is only one variable required, that is Rn
Rn: defines next frame expected, belongs to Receive Window.
l The sequence numbers to the left of the window belong to the frames already received
and acknowledged.
l The sequence numbers to the right of this window define the frames that cannot be
received.
l Any received frame with a sequence number in these two regions is discarded.
l Only a frame with a sequence number matching the value of Rn is accepted and
acknowledged. (i.e. Sn=Rn)
l The receive window slides only one slot at a time, when the correct frame is received the
window slides.
KMIT/CSE/III-I 13
Timers
The timer for the first outstanding frame always expires first.We send all outstanding frames
when this timer expires.
Acknowledgment
l The receiver sends a positive acknowledgment if a frame has arrived safe and sound and
in order.
l If a frame is damaged or frame is received out of order, the receiver is silent and will
discard all subsequent frames until it receives the one it is expecting.
l The silence of the receiver causes the timer of the unacknowledged frame at the sender
site to expire. This causes the sender to go back and resend all frames, beginning with the
one with the expired timer.
l The receiver does not have to acknowledge each frame received. It can send one
cumulative acknowledgment for several frames.
Retransmission (Resending a Frame)
When the timer expires, the sender resends all outstanding frames.
Example:
l Suppose the sender has already sent frame 6, but the timer for frame 3 expires.
l This means that frame 3 has not been acknowledged.
l The sender goes back and sends frames 3, 4,5, and 6 again.
l That is why the protocol is called Go-Back-N ARQ.
Flow Diagram
The below shows what happens when a frame is lost.
l Frames 0, 1, 2, and 3 are sent.
l Frame 0 is acknowledged but Frame 1 is lost.
l The receiver receives frames 2 and 3, but they are discarded because they are received out
of order (frame 1 is expected).
l The sender receives no acknowledgment about frames 1, 2, or 3.
l Its timer finally expires. The sender sends all outstanding frames (1, 2, and 3) because it
does not know whether the frame is lost or corrupted.
l Note that the resending of frames l, 2, and 3 is the response to one single event.
l When the sender is responding to this event, it cannot accept the triggering of other
events.
l This means that when ACK 2 arrives, the sender is still busy with sending frame 3.
l The physical layer must wait until this event is completed and the data link layer goes
back to its sleeping state.
l Vertical line in the figure is to indicate the delay.
Note that before the second timer expires, all outstanding frames have been sent and the timer
is stopped.
KMIT/CSE/III-I 14
Disadvantage with Go-Back-N ARQ
Go-Back-N ARQ protocol is very inefficient for a noisy link.
l Go-Back-N ARQ simplifies the process at the receiver site.
l The receiver keeps track of only one variable, and there is no need to buffer out-of-order
frames and they are simply discarded.
l In a noisy link a frame has a higher probability of damage; so it leads to the resending of
multiple frames.
l This resending uses more bandwidth and slows down the transmission. This is a major
disadvantage.
Solution: When there is just one frame is damaged, then only the damaged frame is resent,
instead of resending from Nth frame. This will be achieved by using Selective Repeat ARQ
Protocol.
6. What is the purpose of CSMA/CD? And Explain it.
KMIT/CSE/III-I 15
l At time t 1, station A has executed its persistence procedure and starts sending the bits of
its frame.
l At time t2, station C has not yet sensed the first bit sent by A.
l Station C executes its persistence procedure and starts sending the bits in its frame, which
propagate both to the left and to the right.
l The collision occurs sometime after time t2 Station C detects a collision at time t3 when
it receives the first bit of A's frame. Station C immediately aborts transmission.
l Station A detects collision at time t4 when it receives the first bit of C's frame; it also
immediately aborts transmission.
l A transmits for the duration t4 – t1; C transmits for the duration t3 - t2
l At time t4, the transmission of A‟s frame is aborted; at time t3, the transmission of C's
frame is aborted. Both are incomplete.
l This is so because the station, once the entire frame is sent, does not keep a copy of
the frame and does not monitor the line for collision detection.
KMIT/CSE/III-I 16
Minimum Frame Size (2Tp)
If the two stations involved in a collision are the maximum distance apart, the signal from the
first station takes Tp time to reach the second station and the effect of the collision takes
another Tp time to reach the first station.
Therefore, the frame transmission time Tfr must be at least two times the maximum
propagation time Tp. So the first station must still be transmitting after 2Tp .
Procedure
l We need to sense the channel before we start sending the frame by using one of the
persistence processes.
l In ALOHA, we first transmit the entire frame and then wait for an acknowledgment. In
CSMA/CD, transmission and collision detection is a continuous process.
l We do not send the entire frame and then look for a collision. The station transmits and
receives continuously and simultaneously using two different ports.
l We use a loop to show that transmission is a continuous process.
l We constantly monitor in order to detect one of two conditions:
either transmission is finished or a collision is detected. Either event stops transmission.
l When we come out of the loop, if a collision has not been detected, it means that
transmission is complete; the entire frame is transmitted. Otherwise, a collision has
occurred.
l Here we send a short jamming signal that enforces the collision in case other stations
have not yet sensed the collision.
KMIT/CSE/III-I 17
7. Explain and demonstrate Selective repeat sliding window Protocol with an example.
It is more efficient for Noisy links but processing at the receiver is more complex.
Design Window
Sizes
Window size 2m-1 means the size of the sender and receiver window is at most one half of 2m
(i.e 2m/2).
KMIT/CSE/III-I 18
Windows
It uses two windows:
1. Send Window
2. Receive Window
The size of the send window and receive window is same as 2m-1.
Example: If m = 4, the sequence numbers ranges from 0 to 15, but the size of the window is
just 8.
KMIT/CSE/III-I 19
l The Selective Repeat Protocol allows as many frames as the size of the receive window to
arrive out of order and be kept until there is a set of in-order frames to be delivered to the
network layer.
l Because the sizes of the send window and receive window are the same, all the frames in
the send frame can arrive out of order and be stored until they can be delivered.
l We need to mention that the receiver never delivers packets out of order to the network
layer.
l Those slots inside the receive window that are colored define frames that have arrived out
of order and are waiting for their neighbors to arrive before delivery to the network layer.
Sender site:
l For every request event a timer is started before sending any frame. The arrival event is
more complicated. An ACK or a NAK frame may arrive at the sender site.
l If a valid NAK frame arrives, we just resend the corresponding frame.
l If a valid ACK arrives 3 actions will be done:
1. Purge the buffers
2. Stop the corresponding timer
3. Move the left wall of the window.
l The time-out event is simpler, only the frame which times out is resent.
Receiver site:
l Receiver sends ACK and NAK frames to sender.
l If the Receiver receives a corrupted frame and a NAK has not yet been sent, Receiver
sends a NAK to tell the sender that we have not received the frame we expected.
l If the frame is not corrupted and the sequence number is in the window, Receiver stores
the frame and marks the slot.
l If contiguous frames, starting from Rn have been marked, Data link layer delivers their
data to the network layer and slide the window.
Flow Diagram
By looking at the below flow diagram, we can observe below points:
KMIT/CSE/III-I 20
Timers
l Each frame sent or resent needs a timer and the timers needs to be numbered such as
0,1,2,3..etc.
l The timer for frame 0 starts at the first request, but stops when the ACK for this frame
arrives.
l The timer for frame 1 starts at the second request and restarts when a NAK arrives, and
finally stops when the last ACK arrives.
l The other two timers start when the corresponding frames are sent and stop at the last
arrival event.
Receiver Site
l At the receiver site we need to distinguish between the acceptance of a frame and its
delivery to the network layer.
l At the second arrival, frame 2 arrives and is stored and marked (colored slot), but it
cannot be delivered because frame 1 is missing.
l At the next arrival, frame 3 arrives and is marked and stored, but still none of the frames
can be delivered.
l Only at the last arrival, when finally a copy of frame 1 arrives and frames 1, 2, and 3 be
delivered to the network layer.
l There are two conditions for the delivery of frames to the network layer:
i. a set of consecutive frames must have arrived.
ii. the set starts from the beginning of the window.
l After the first arrival, there was only one frame and it started from the beginning of the
window.
l After the last arrival, there are three frames and the first one starts from the beginning of
the window.
Importance of NAK’s
l Here a NAK is sent after the second arrival, but not after the third.
l The reason is that the protocol does not want to crowd the network with unnecessary
NAKs and unnecessary resent frames.
l The second NAK would still be NAK1 to inform the sender to resend frame 1 again; this
has already been done.
l The first NAK sent is remembered and is not sent again until the frame slides.
l A NAK is sent once for each window position and defines the first slot in the window.
Importance of ACK’s
l There are only two ACKs are sent here. The first one acknowledges only the first frame
The second one acknowledges three frames.
l In Selective Repeat, ACKs are sent when data are delivered to the network layer.
l If the data belonging to n frames are delivered in one shot, only one ACK is sent for all of
them.
l In the above figure frame 1,2,3, are sent to Network layer and then ACK4 is sent, to
represent that Frame1, Frame2, Frame3 are delivered.
KMIT/CSE/III-I 21
There is a question arises that :
Why the size of the sender and receiver windows is 2m-1?
Sol: For an example, take m = 2, which means the size of the window is 2m/2, or 2.
Now we compare window size=2 and window size =3.
Window size=2
l If the size of the window is 2 and all acknowledgments are lost, the timer for frame 0
expires and frame 0 is resent.
l The window of the receiver is now expecting frame 2, not frame 0, so this duplicate frame
is correctly discarded.
Window Size=3
l When the size of the window is 3 and all acknowledgments are lost, the sender sends a
duplicate of frame 0.
l However, this time, the window of the receiver expects to receive frame 0 (0 is part of the
window), so it accepts frame 0, not as a duplicate, but as the first frame in the next cycle.
l This is clearly an error.
1. Repeater – A repeater operates at the physical layer. Its job is to regenerate the signal over the same network
before the signal becomes too weak or corrupted so as to extend the length to which the signal can be transmitted
over the same network.
2. Hub – A hub is basically a multiport repeater. A hub connects multiple wires coming from different branches,
for example, the connector in star topology which connects different stations. Hubs cannot filter data, so data
packets are sent to all connected devices.
3. Bridge – A bridge operates at data link layer. A bridge is a repeater, with add on the functionality of filtering
content by reading the MAC addresses of source and destination. It is also used for interconnecting two LANs
working on the same protocol. It has a single input and single output port, thus making it a 2 port device.
Transparent Bridges:- These are the bridge in which the stations are completely unaware of the
bridge’s existence i.e. whether or not a bridge is added or deleted from the network, reconfiguration of
the stations is unnecessary. These bridges make use of two processes i.e. bridge forwarding and bridge
learning.
KMIT/CSE/III-I 22
4. Switch – A switch is a multiport bridge with a buffer and a design that can boost its efficiency(a large number of
ports imply less traffic) and performance. A switch is a data link layer device. The switch can perform error
checking before forwarding data, that makes it very efficient as it does not forward packets that have errors and
forward good packets selectively to correct port only.
5. A router is a network layer hardware device that transmits data from one LAN to another if both networks
support the same set of protocols. So a router is typically connected to at least two LANs and the internet
service provider (ISP). It receives its data in the form of packets, which are data frames with their destination
address added. Router also strengthens the signals before transmitting them. That is why it is also
called repeater.
Routing Table
A router reads its routing table to decide the best available route the packet can take to reach its destination
quickly and accurately. The routing table may be of these two types −
Static − In a static routing table the routes are fed manually. So it is suitable only for very small networks
that have maximum two to three routers.
Dynamic − In a dynamic routing table, the router communicates with other routers through protocols to
determine which routes are free. This is suited for larger networks where manual feeding may not be
feasible due to large number of routers.
6. Gateway
Gateway is a network device used to connect two or more dissimilar networks. In networking parlance, networks
that use different protocols are dissimilar networks. A gateway usually is a computer with
multiple NICs connected to different networks. A gateway can also be configured completely using software. As
networks connect to a different network through gateways, these gateways are usually hosts or end points of the
network.
Gateway uses packet switching technique to transmit data from one network to another. In this way it is similar
to a router, the only difference being router can transmit data only over networks that use same protocols.
VLANS
Virtual Local Area Networks or Virtual LANs (VLANs) are a logical group of computers that appear to be on the
same LAN irrespective of the configuration of the underlying physical network.
Network administrators partition the networks to match the functional requirements of the VLANs so that each
VLAN comprise of a subset of ports on a single or multiple switches or bridges.
This allows computers and devices in a VLAN to communicate in the simulated environment as if it is a separate
LAN.
KMIT/CSE/III-I 23
VLANs eliminate the requirement to run new cables or reconfiguring physical connections in the present
network infrastructure.
KMIT/CSE/III-I 24