cn-unit-2-computer-networks
cn-unit-2-computer-networks
To accomplish these goals, the data link layer takes the packets it gets from the network layer and
encapsulates them into frames for transmission. Each frame contains a frame header, a payload field for holding
the packet, and a frame trailer, as illustrated in Fig.
FRAMING
To provide service to the network layer, the data link layer must use the service provided to it by the
physical layer. What the physical layer does is accept a raw bit stream and attempt to deliver it to the
destination. If the channel is noisy, as it is for most wireless and some wired links, the physical layer will add
some redundancy to its signals to reduce the bit error rate to a tolerable level. However, the bit stream received
by the data link layer is not guaranteed to be error free. Some bits may have different values and the number of
bits received may be less than, equal to, or more than the number of bits transmitted. It is up to the data link
layer to detect and, if necessary, correct errors.
The data link layer to break up the bit stream into discrete frames, compute a short token called a
checksum for each frame, and include the checksum in the frame when it is transmitted.
When a frame arrives at the destination, the checksum is recomputed. If the newly computed checksum
is different from the one contained in the frame, the data link layer knows that an error has occurred and takes
steps to deal with it.
DLL translates the physical layer's raw bit stream into discrete units (messages) called frames.
A good design must make it easy for a receiver to find the start of new frames while using little of
the channel bandwidth. We will look at four methods:
1. Byte count.
2. Flag bytes with byte stuffing.
3. Flag bits with bit stuffing.
4. Physical layer coding violations.
ERROR CONTROL:
Error control is concerned with ensuring that all frames are eventually delivered (possibly in order) to a
destination. How? Three items are required.
• Acknowledgements: Typically, reliable delivery is achieved using the “acknowledgments
with retransmission" paradigm, whereby the receiver. returns a special
acknowledgment
(ACK) frame to the sender indicating the correct receipt of a frame. In some systems, the receiver
also returns a negative acknowledgment (NACK) for incorrectly-received frames. This is
nothing more than a hint to the sender so that it can retransmit a frame right away without
waiting for a timer to expire.
FLOW CONTROL:
Flow control deals with controlling the speed of the sender to match that of the receiver.
Two Approaches:
feedback-based flow control, the receiver sends back information to the sender
giving it permission to send more data or at least telling the sender how the
receiver is doing
rate-based flow control, the protocol has a built-in mechanism that limits the
rate at which senders may transmit data, without using feedback from the
receiver.
TYPES OF ERRORS:
There are two main types of errors in transmissions:
1. Single bit error: It means only one bit of data unit is changed from 1 to 0 or from
0 to 1.
2. Burst error: It means two or more bits in data unit are changed from 1 to 0 from 0 to
1. In burst error, it is not necessary that only consecutive bits are changed.
The length of burst error is measured from first changed bit to last changed
bit
Error Correcting Codes: Include enough redundancy to detect and correct errors.
ERROR-DETECTING CODES:
Error detection means to decide whether the received data is correct or not without having a copy of the
original message. Error detection uses the concept of redundancy, which means adding extra bits for detecting
errors at the destination.
The problem with parity is that it can only detect odd numbers of bit substitution errors, i.e. 1 bit, 3bit, 5,
bit, etc. Errors. If there two, four, six, etc. bits which are transmitted in error, using VRC will not be
able to detect the error.
When the polynomial code method is employed, the sender and receiver must agree upon a generator
polynomial, G(x), in advance. Both the high- and low order bits of the generator must be 1. To compute the
CRC for some frame with m bits corresponding to the polynomial M(x), the frame must be longer than the
generator polynomial. The idea is to append a CRC to the end of the frame in such a way that the polynomial
represented by the check summed frame is divisible by G(x). When the receiver gets the check summed frame,
it tries dividing it by G(x). If there is a remainder, there has been a transmission error.
The algorithm for computing the CRC is as follows:
1. Let r be the degree of G(x). Append r zero bits to the low-order end of the frame so it now
contains m + r bits and corresponds to the polynomial xrM(x).
2. Divide the bit string corresponding to G(x) into the bit string corresponding to xrM(x), using
modulo 2 divisions.
It should be clear that T(x) is divisible (modulo 2) by G(x). In any division problem, if you diminish the
dividend by the remainder, what is left over is divisible by the divisor.
Example of CRC:
4. CHECKSUM:
• Checksum is the error detection scheme used in IP, TCP & UDP.
• Here, the data is divided into k segments each of n bits. In the sender’s end the segments are
added using 1’s complement arithmetic to get the sum. The sum is complemented to get the
checksum. The checksum segment is sent along with the data segments
• At the receiver’s end, all received segments are added using 1’s complement arithmetic to get
the sum. The sum is complemented. If the result is zero, the received data is accepted; otherwise
discarded
• The checksum detects all errors involving an odd number of bits. It also detects most
errors involving even number of bits.
Diagrammatic approach:
NOISELESS CHANNELS:
Let us first assume we have an ideal channel in which no frames are lost, duplicated, or corrupted. We
introduce two protocols for this type of channel. The first is a protocol that does not use flow control; the second is
the one that does. Of course, neither has error control because we have assumed that the channel is a perfect
noiseless channel.
Simplest Protocol:
Our first protocol, which we call the Simplest Protocol for lack of any other name, is one that has no flow or
error control. Like other protocols we will discuss in this chapter, it is a unidirectional protocol in which data
frames are traveling in only one direction-from the sender to receiver. We assume that the receiver can
immediately handle any frame it receives with a processing time that is small enough to be negligible. The data
link layer of the receiver immediately removes the header from the frame and hands the data packet to its
network layer, which can also accept the packet immediately. In other words, the receiver can never be
overwhelmed with incoming frames.
Design
There is no need for flow control in this scheme. The data link layer at the sender site gets data from its network
layer, makes a frame out of the data, and sends it. The data link layer at the receiver site receives a frame from
its physical layer, extracts data from the frame, and delivers the data to its network layer. The data link layers of
the sender and receiver provide transmission services for their network layers.
Analysis The algorithm has an infinite loop, which means lines 3 to 9 are repeated forever once the program
starts. The algorithm is an event-driven one, which means that it sleeps (line 3) until an event wakes it up (line 4).
This means that there may be an undefined span of time between the execution of line 3 and line 4; there is a
gap between these actions. When the event, a request from the network layer, occurs, lines 6 through 8 are
executed. The program then repeats The loop and again sleeps at line 3 until the next occurrence of the event.
We have written pseudo code for the main process. We do not show any details for the modules Get Data,
Make Frame, and Send Frame.
Analysis This algorithm has the same format as above Algorithm except that the direction of the frames and
data is upward. The event here is the arrival of a data frame. After the event occurs, the data link layer receives
the frame from the physical layer using the ReceiveFrame() process, extracts the data from the frame using the
ExtractData() process, and delivers the data to the network layer using the DeliverData() process. Here, we also
have an event-driven algorithm because the algorithm never knows when the data frame will arrive.
Example:
Below Figure shows an example of communication using this protocol. It is very simple. The sender sends a
sequence of frames without even thinking about the receiver. To send three frames, three events occur at the
sender site and three events at the receiver site. Note that the data frames are shown by tilted boxes; the height
of the box defines the transmission time difference between the first bit and the last bit in the frame.
Design
We can see the traffic on the forward channel (from sender to receiver) and the reverse channel. At any time,
there is either one data frame on the forward channel or one ACK frame on the reverse channel. We
therefore need a half-duplex link.
Algorithms
Sender-site algorithm for Stop-and- Wait Protocol
Analysis This is very similar to above Algorithm with one exception. After the data frame arrives, the receiver
sends an ACK frame (line 9) to acknowledge the receipt and allow the sender to send the next frame.
Example:
Below Figure shows an example of communication using this protocol. It is still very simple. The sender sends
one frame and waits for feedback from the receiver. When the ACK arrives, the sender sends the next frame.
Note that sending two frames in the protocol involves the sender in four events and the receiver in two events.
Although the Stop-and-Wait Protocol gives us an idea of how to add flow control to its predecessor,
noiseless channels are nonexistent. We can ignore the error (as we sometimes do), or we need to add error
control to our protocols. We discuss three protocols in this section that use error control.
Sequence Numbers
As we discussed, the protocol specifies that frames need to be numbered. This is done by using
sequence numbers. A field is added to the data frame to hold the sequence number of that frame.
One important consideration is the range of the sequence numbers. Since we want to minimize the frame
size, we look for the smallest range that provides unambiguous communication. The sequence numbers of
course can wrap around. For example, if we decide that the field is m bits long, the sequence numbers start from
0, go to 2m - 1, and then are repeated.
Acknowledgment Numbers
Since the sequence numbers must be suitable for both data frames and ACK frames, we use this
convention: The acknowledgment numbers always announce the sequence number of the next frame expected
by the receiver. For example, if frame 0 has arrived safe and sound, the receiver sends an ACK frame with
acknowledgment 1 (meaning frame 1 is expected next). If frame 1 has arrived safe and sound, the receiver
sends an ACK frame with acknowledgment 0 (meaning frame 0 is expected).
Design
Below Figure shows the design of the Stop-and-WaitARQ Protocol. The sending device keeps a copy of
the last frame transmitted until it receives an acknowledgment for that frame. A data frames uses a seqNo
(sequence number); an ACK frame uses an ackNo (acknowledgment number). The sender has a control
variable, which we call Sn (sender, next frame to send), that holds the sequence number for the next frame to be
sent (0 or 1).
The receiver has a control variable, which we call Rn (receiver, next frame expected), that holds the
number of the next frame expected. When a frame is sent, the value of Sn is incremented (modulo-2), which
means if it is 0, it becomes 1 and vice versa. When a frame is received, the value of Rn is incremented (modulo-
2), which means if it is 0, it becomes 1 and vice versa. Three events can happen at the sender site; one event can
happen at the receiver site. Variable Sn points to the slot that matches the sequence number of the frame that
has been sent, but not acknowledged; Rn points to the slot that matches the sequence number of the expected
frame.
Analysis This is noticeably different from Algorithm 11.4. First, all arrived data frames that are corrupted are
ignored. If the seqNo of the frame is the one that is expected (Rn ), the frame is accepted, the data are delivered
to the network layer, and the value of Rn is incremented. However, there is one subtle point here. Even if the
sequence number of the data frame does not match the next frame expected, an ACK is sent to the sender. This
ACK, however, just reconfirms the previous ACK instead of confirming the frame received. This is done
because the receiver assumes that the previous ACK might have been lost; the receiver is sending a duplicate
frame. The resent ACK may solve the problem before the time-out does it.
Efficiency
The Stop-and-Wait ARQ discussed in the previous section is very inefficient if our channel is thick and
long. By thick, we mean that our channel has a large bandwidth; by long, we mean the round-trip delay is long.
The product of these two is called the bandwidth delay product, as we discussed in Chapter 3. We can think of
the channel as a pipe. The bandwidth-delay product then is the volume of the pipe in bits. The pipe is always
there. If we do not use it, we are inefficient. The bandwidth-delay product is a measure of the number of bits we
can send out of our system while waiting for news from the receiver.
Example
Below Figure shows an example of Stop-and-Wait ARQ. Frame a is sent and acknowledged. Frame 1 is
lost and resent after the time-out. The resent frame 1 is acknowledged and the timer stops. Frame a is sent and
Pipelining
In networking and in other areas, a task is often begun before the previous task has ended. This is
known as pipelining. There is no pipelining in Stop-and-Wait ARQ because we need to wait for a frame to
reach the destination and be acknowledged before the next frame can be sent. However, pipelining does apply
to our next two protocols because several frames can be sent before we receive news about the previous frames.
Pipelining improves the efficiency of the transmission if the number of bits in transition is large with respect to
the bandwidth-delay product.
Sequence Numbers
Frames from a sending station are numbered sequentially. However, because we need to include the
sequence number of each frame in the header, we need to set a limit. If the header of the frame allows m bits for
the sequence number, the sequence numbers range from 0 to 2m - 1. For example, if m is 4, the only sequence
numbers are 0 through 15 inclusive. However, we can repeat the sequence. So the sequence numbers are
0, 1,2,3,4,5,6, 7,8,9, 10, 11, 12, 13, 14, 15,0, 1,2,3,4,5,6,7,8,9,10, 11, ...
In m
other words, the sequence numbers are modulo-2
.
The receive window makes sure that the correct data frames are received and that the correct
acknowledgments are sent. The size of the receive window is always 1. The receiver is always looking for the
arrival of a specific frame. Any frame arriving out of order is discarded and needs to be resent. Below figure
shows the receive window.
We need only one variable Rn (receive window, next frame expected) to define this abstraction. The
sequence numbers to the left of the window belong to the frames already received and acknowledged; the
sequence numbers to the right of this window define the frames that cannot be received. Any received frame
with a sequence number in these two regions is discarded. Only a frame with a sequence number matching the
value of Rn is accepted and acknowledged.
Acknowledgment
The receiver sends a positive acknowledgment if a frame has arrived safe and sound and in order. If a frame is
damaged or is received out of order, the receiver is silent and will discard all subsequent frames until it receives
the one it is expecting. The silence of the receiver causes the timer of the unacknowledged frame at the sender
site to expire. This, in turn, causes the sender to go back and resend all frames, beginning with the one with the
expired timer. The receiver does not have to acknowledge each frame received. It can send one cumulative
acknowledgment for several frames.
Resending a Frame
When the timer expires, the sender resends all outstanding frames. For example, suppose the sender has already
sent frame 6, but the timer for frame 3 expires. This means that frame 3 has not been acknowledged; the sender
goes back and sends frames 3, 4,5, and 6 again. That is why the protocol is called Go-Back-N ARQ.
Design
Below Figure shows the design for this protocol. As we can see, multiple frames can be in transit in the forward
direction, and multiple acknowledgments in the reverse direction. The idea is similar to Stop-and- Wait ARQ;
the difference is that the send window allows us to have as many frames in transition as there are slots in the
send window.
Analysis this algorithm first initializes three variables. Unlike Stop-and-Wait ARQ, this protocol allows several
requests from the network layer without the need for other events to occur; we just need to be sure that the
window is not full (line 12). In our approach, if the window is full, the request is just ignored and the network
layer needs to try again. Some implementations use other methods such as enabling or disabling the network
layer. The handling of the arrival event is more complex than in the previous protocol. If we receive a corrupted
ACK, we ignore it.
Example
Below Figure shows an example of Go-Back-N. This is an example of a case where the forward channel
is reliable, but the reverse is not. No data frames are lost, but some ACKs are delayed and one is lost. The
example also shows how cumulative acknowledgments can help if acknowledgments are delayed or lost.
After initialization, there are seven sender events. Request events are triggered by data from the network
layer; arrival events are triggered by acknowledgments from the physical layer. There is no time-out event here
because all outstanding frames are acknowledged before the timer expires. Note that although ACK 2 is lost,
ACK 3 serves as both ACK 2 and ACK3.
The receive window in Selective Repeat is totally different from the one in GoBack-N. First, the size of
the receive window is the same as the size of the send window (2m- I ). 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. Because the sizes of the send window and receive window are the
same.
Algorithms
Sender-side Selective Repeat algorithm
Example
This example is similar to go back N Example in which frame 1 is lost. We show how Selective Repeat behaves
in this case. Below Figure shows the situation.
o Aloha
o CSMA
o CSMA/CD
o CSMA/CA
It is designed for wireless LAN (Local Area Network) but can also be
used in a shared medium to transmit data. Using this method, any
station can transmit data across a network simultaneously when a data
frameset is available for transmission.
Aloha Rules
Slotted Aloha
Non-Persistent: It is the access mode of CSMA that defines before transmitting the data,
each node must sense the channel, and if the channel is inactive, it immediately sends the data.
Otherwise, the station must wait for a random time (not continuously), and when the channel
is found to be idle, it transmits the frames.
CSMA/ CD
CSMA/ CA
Interframe space: In this method, the station waits for the channel
to become idle, and if it gets the channel is idle, it does not
immediately send the data. Instead of this, it waits for some time, and
this time period is called the Interframe space or IFS. However, the
IFS time is often used to define the priority of the station.
In the Controlled access technique, all stations need to consult with one
another in order to find out which station has the right to send the data.
1. Reservation
2. Polling
3. Token Passing
1. Reservation
2. Polling
The polling method mainly works with those topologies where one
device is designated as the primary station and the other device is
designated as the secondary station.
All the exchange of data must be made through the primary device even
though the final destination is the secondary device.
Thus to impose order on a network that is of independent users, and in
order to establish one station in the network that will act as a
controller and periodically polls all other stations is simply referred to
as polling.
Poll Function
In case if primary devices want to receive the data, then it usually asks the
secondary devices if they have anything to send. This is commonly known
as Poll Function.
In case, if the primary device wants to send the data then it tells the
secondary devices in order to get ready to receive the data. This is
commonly known as the Select function.
Thus the select function is used by the primary device when it has
something to send.
We had already told you that the primary
device always controls the link.
Before sending the data frame, a select (SEL ) frame is created and
transmitted by the primary device, and one field of the SEL frame
includes the address of the intended secondary.
Advantages of Polling
Drawbacks
There are some cons of the polling method and these are as follows:
3. Token Passing
In the token passing methods, all the stations are organized in the form of
a logical ring. We can also say that for each station there is a predecessor
and a successor.
The predecessor is the station that is logically before the station in the
ring; while the successor is the station that is after the station in the
ring. The station that is accessing the channel now is the current
station.
Basically, a special bit pattern or a small message that circulates from
one station to the next station in some predefined order is commonly
known as a token.
Possessing the token mainly gives the station the right to access the
channel and to send its data.
When any station has some data to send, then it waits until it receives a
token from its predecessor. After receiving the token, it holds it and
then sends its data. When any station has no more data in order to send
then it releases the token and then passes the token to the next logical
station in the ring.
Also, the station cannot send the data until it receives the token again
in the next round.
In Token passing, when a station receives the token and has no data to
send then it just passes the token to the next station.
The problem that occurs due to the Token passing technique is the
duplication of tokens or loss of tokens. The insertion of the new station,
removal of a station, also needs to be tackled for correct and reliable
operation of the token passing technique.
MAC Addresses
when forwarding a packet with IP, a router knows when the packet
has reached its destination network
how can the router determine the associated MAC address for a given
IP address?
when forwarding a packet with IP, a router knows when the packet
has reached its destination network
ARP table
entry IP
address MAC
address
all hosts hear query and response, cache translations for A and B in their ARP tables
all hosts process all ARP packets, even if not addressed to themselves
ARP Example
Ethernet
dominant wired LAN technology
very inexpensive: $20 for 100
Mbps
simpler and cheaper than FDDI (token ring), ATM
speeds have improved dramatically over the years: 10 Mbps - 10 Gbps
Ethernet Topologies
Example Configuration
Switch Example
motivation
want to isolate tra c for small subnets, without requiring a separate, physical
switch for each subnet
rewiring them use a single switch with intelligence that knows which ports
belong to which VLAN use a router within the switch to route between
VLANs