0% found this document useful (0 votes)
5 views34 pages

Paper C7 Computer Network Assignments

The document outlines various error detection and control techniques in data communication, including Cyclic Redundancy Check (CRC), Stop and Wait ARQ, Go Back N ARQ, and Selective Repeat ARQ. It explains the algorithms and processes involved in each technique, emphasizing the importance of reliable data transmission and error correction. Additionally, it discusses Dijkstra's Algorithm for computing the shortest path in a network, detailing its operation and use in routing tables.

Uploaded by

Abhinav Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views34 pages

Paper C7 Computer Network Assignments

The document outlines various error detection and control techniques in data communication, including Cyclic Redundancy Check (CRC), Stop and Wait ARQ, Go Back N ARQ, and Selective Repeat ARQ. It explains the algorithms and processes involved in each technique, emphasizing the importance of reliable data transmission and error correction. Additionally, it discusses Dijkstra's Algorithm for computing the shortest path in a network, detailing its operation and use in routing tables.

Uploaded by

Abhinav Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Question 1 - Simulate Cyclic Redundancy Check error

detection technique

● It is one of the most powerful and commonly used error detection technique
/code
● Basic Approach
● Given an m-bit block of bits, the sender generates an n-bit sequence, known as
frame check sequence (FCS).
● The result frame consists of m bits data +n bits FCS.
● It is divisible by a some predetermined number.
● The receiver divides the incoming frame by the same number and if there is no
remainder, it assumes no error and accept data.
CRC – [Data- m bits and divisor – n+1 bits]

● Sender’s End ● Receiver’s End


● 1. Add n zeroes to m bit ● 1. Divide the received
data data by n+1 bit divisor
● 2. Divide m+n bit data by ● 2. If there is no
n+1 bit divisor using remainder , it means no
modulo 2 division to error in data so accept
compute n bit CRC. data otherwise reject
● 3. Send Data and CRC data.

Data CRC
CRC - Example

● Division based on ● 1001


modulo 2 arithmetic ● 1011
● Data : 1010 1010000
XOR 1011
● Divisor : 1011
0010
● Add 3 zeroes to data
0000
● Dividend : 1010000
0100
● CRC- 0111 0000
● Data to Send 1000
1010 011
1011
CRC 011
CRC - Algorithm

/* data array stores m-bit data for which we have i←0


to compute cyclic redundancy check and divisor
array stores n+1 bit divisor */
for j ←m to m+n-1
// Add n zeroes to data
for i ← m to m+n-1
{
{ data[i] ← 0 } CRC[i]←data[j]
for i ← 0 to m -1
i←i+1
{
}
if data[i]!=0
{ for j ← 0 to n //CRC array stores computed CRC
{
/* for data 11000 and divisor 1011
data[i+j]← data[i+j]XOR divisor[j]
CRC is computed as using this
}
algorithm 100*/
}
} //Compute CRC using modulo 2 division
Question 2 Simulate Stop and wait ARQ Flow and Error
control technique

● Reason
● For reliable and efficient data communication a great deal of coordination is
necessary between sender and receiver. There exists speed and memory
mismatch between sender and receiver device.
● A fast sender should not overwhelm a slow receiver.
● If error occurs during transmission, it is necessary to devise mechanism to
correct it.
● Error can occur any time and any where.
Error Control Technique - ARQ

● Error Detection using CRC, checksum etc


● Positive Acknowledgment ACK for successfully received error free frame
● Negative Acknowledgment NAK for frame received with error. The sender
retransmits such frame.
● Timeout and retransmission of Lost Frame – The sender maintains a timer for
frame sent and if does not receive any acknowledgement (ACK or NAK), it
assumes frame lost in transit and timeouts and retransmits frame.
Stop and wait ARQ

● It is based on stop and wait flow control.


● The source station transmits a single frame and then waits for an ACK
● No other data frame can be sent until the destination station reply arrives at the
source station.
● Source and destination are equipped with timer to take care of lost frame.
● If no recognizable ACK is received when the timer expires, the same frame is
sent again
Stop and wait flow ARQ
Sender Receiver

Frame 0

ACK 1

Frame 1

ACK 0
Stop and Wait ARQ Algorithm
Sender’s End
//SN store frame sequence number if(response=ACKFrame)

// N is total number of frames to send {

// Data array stores data frames to send // send next frame for positive ACK

SN ← 0 i← i+1

i←0 SN ← (SN+1)%2

while (i <= N) }

{ if(response=NAKFrame)

sframe ← create new frame {

sframe.data ← data[i] // resend previous frame for negative ACK

sframe.sequenceNo ← SN }

sendFrame(sframe) }

response ← receiveResponse()
Stop and Wait ARQ Algorithm
Receiver’s End
// N is total number of frames to receive if(CRC=0)
{
// Data array stores received data frames
// send ACK, accept data and prepare for next
i←0 frame

while (i <= N) ACKFrame ← create ACK frame


sendResponse(ACKFrame)
{
data[i] ← rFrame.data
rframe ← receiveFrame()
i← i+1
//compute CRC to detect error in frame
}
CRC ← computeCRC(rframe) else

/* if CRC is zero it means error free frame {

so send positive acknowledgement ACK else // send NAK and prepare for the same frame
send negative acknowledgement NAK */ NAKFrame ← create NAK frame
sendResponse(NAKFrame)
}
}
Question 3 Simulate Go Back N ARQ Sliding Window Flow
Control based error control technique

● Stop and wait does not utilizes link bandwidth efficiently


● It allows only one frame in the transit at a time.
● Sliding window allows multiple frames to be in the transit at the same time
Sliding Window

● Sender’s Side ● Receiver’s Side


● Sender sends sequentially ● Receiver also maintains
numbered frames. window of size 1.
● K bits are allowed in header for ● The receiver acknowledges a
frame sequence number.
frame by sending an ACK
● For k bits sequence number can frame that includes the
be 0 to 2K-1
sequence number of the next
● Sender maintains sender
frame expected.
window. It is the list of frame
sequence numbers that is ● The sender can acknowledge
allowed to send. multiple frames by withholding
● The size of window <=2k-1 ACK.
● The sender is also provided with ● The receiver maintains a
a buffer equal to the size of buffer of size 1.
window size.
Go Back N ARQ

● It is based on sliding window flow control


● It is most commonly used technique.
● Source station may send a series of multiple frames sequentially up to a maximum
number.
● In case of error free frame, the destination will acknowledge the frames like sliding
window flow control.
● If the destination detects an error in a frame or it receives a frame out of order, it
sends a NAK for that frame called REJ (reject).
● The destination will discard the frame in error and all subsequent frames until the
frame in error is correctly received.
● The source station on receiving a REJ must retransmit the frame in error and all the
subsequent frames. [Go Back to N frame in error and retransmit all]
● Receiver never accepts out of order frames
Go Back N ARQ Example k=3 bit, window size=3
Sender Receiver

F0
F1
F2

ACK3

F3
Error in F3
F4 NAK3
Go Back N All subsequent discarded
F5
(frame 3)
And retransmit F3
frame N and all F4
subsequent F5
frames
Go Back N ARQ Algorithm
Sender’s End
/*SN store frame sequence number N is total if(response=ACKFrame)
number of frames to send and Data array stores
data frames to send*/ {
SN ← 0 , i ← 0 // send next set of frame for positive ACK
while (i <= N) }
{ if(response=NAKFrame)
for j← 0 to windowSize - 1 {
{ sframe ← create new frame // Go Back to frame with seuqnece Number N
sframe.data ← data[i] for negative ACK

sframe.sequenceNo ← SN SN ← response.sequenceNo

sendFrame(sframe) i ← i-(windowSize - SN)

SN ← (SN+1)%windowSize }

response ← receiveResponse() , i ← i+1 }


}
Go Back N ARQ Algorithm
Receiver’s End
// N is total number of frames to receive if(CRC=0 and newSN=oldSN+1)
// Data array stores data received frames {
i ← 0, SN ← 0 data[i] ← rframe.data
while (i <= N) i← i+1
{
}
oldSN ← SN
else
for j=0 to windowSize-1
{
{ rframe ← receiveFrame()
// send NAK and go back to Nth frame
//compute CRC to detect error in frame
NAKFrame ← create NAK frame
CRC ← computeCRC(rframe),
NAKFrame.sequenceNo ← oldSN
newSN ← rframe.sequenceNo
sendResponse(NAKFrame)
/*if CRC is zero and frame is not out of
sequence it means error free frame so accept break loop //discard remaining frames
else reject and also discard future frames*/
}
Go Back N ARQ Algorithm
Receiver’s End
if(j=windowSize)
{
/* if all the frames are received error free then send cumulative
acknowledgement for next frame to receive*/
ACKFrame ← create ACK Frame
ACKFrame.acknowledgementNo ← (newSN+1)%windowSize
}
}
Question 4 Simulate Selective Repeat ARQ Sliding
Window Flow Control based error control technique

● It is based on sliding window flow control


● It is most commonly used technique.
● Source station may send a series of multiple frames sequentially upto a maximum number.
● In case of error free frame, the destination will acknowledge the frames like sliding window flow
control.
● If the destination detects an error in a frame or it receives a frame out of order, it sends a NAK
fro that frame called SREJ (Selective Reject).
● The destination will discard the frame in error but it can accept subsequent frames.
● It maintains storage buffer to store out of order frames. It also has the required logic to put
frames in order on the basis of sequence number.
● The source station on receiving a SREJ must retransmit the frame in error only. [Selective
Repeat frame in error]
● Sender is also complex device as it can send out of order frame (error frame)
Selective Repeat ARQ
Example k=3 bit, window size=3
Sender Receiver

F0
F1
F2

ACK3

F3
Error in F3 but
F4 NAK3
Selective Repeat All subsequent accepted
F5
(frame 3)
And retransmit F3
frame 3 only
Selective Repeat ARQ Algorithm
Sender’s End
/*SN store frame sequence number N is total if(response=ACKFrame)
number of frames to send and Data array stores
{
data frames to send*/
// send next set of frame for positive ACK
SN ← 0 , i ← 0
}
while (i <= N)
if(response=NAKFrame)
{
{
for j← 0 to windowSize - 1
// Selective repeat frame with sequence no N for negative
ACK
{ sframe ← create new frame
sframe ← create new frame
sframe.data ← data[i]
sframe.data ← data[i]
sframe.sequenceNo ← SN
sframe.sequenceNo ← SN
sendFrame(sframe)
SN ← (SN+1)%windowSize
SN ← (SN+1)%windowSize
}
response ← receiveResponse() , i ← i+1
}
}
Selective Repeat ARQ Algorithm
Receiver’s End
// N is total number of frames to receive if(CRC=0 and newSN=oldSN+1)
// Data array stores data received frames {
i ← 0, SN ← 0 data[i] ← rframe.data
while (i <= N) i← i+1
{
}
oldSN ← SN
else
for j=0 to windowSize-1
{
{ rframe ← receiveFrame()
// send NAK and go back to Nth frame
//compute CRC to detect error in frame
NAKFrame ← create NAK frame
CRC ← computeCRC(rframe),
NAKFrame.sequenceNo ← oldSN
newSN ← rframe.sequenceNo
sendResponse(NAKFrame)
/*if CRC is zero and frame is not out of
sequence it means error free frame so accept /*accept out of order remaining frames but
else reject and also discard future frames*/ later on put out of order frame in correct
sequence */
}
Selective Repeat ARQ Algorithm
Receiver’s End
if(j=windowSize)
{
/* if all the frames are received error free then send cumulative
acknowledgement for next frame to receive*/
ACKFrame ← create ACK Frame
ACKFrame.acknowledgementNo ← (newSN+1)%windowSize
}
}
Question - 5 Simulate and implement Dijkstra’s Algorithm
for computing shortest path
Dijkstra’s algorithm is used to compute shortest path from a single source node to
all other nodes in the network.

This algorithm is used in Link State Routing.

Based on computed shortest path routing table is prepared by the routers.

The routing table is used for forwarding of incoming packets to outgoing lines.

Routing table contains

1. Destination Node where the packet is to be sent


2. Next Node along the destination node in the network where the packet is
forwarded
Dijkstra’s Algorithm

It uses two lists OPEN and CLOSED.

OPEN is a priority queue whereas CLOSED is just ordinary list.

OPEN is used to store unprocessed nodes and CLOSED is used to store


processed nodes.

This algorithm starts from the start node S and proceeds by selecting a node from
OPEN which has minimum total cost. The cost information is stored in array C.The
algorithm stops when OPEN becomes empty.

The parent information of a node is kept in an array P.

This array can be used to construct complete path from Start bode S to any
destination node.

It can also be used to determine next node along the destination


Dijkstra’s Algorithm

1. Initialize : Set OPEN←{S} and CLOSED←{ }


2. while (OPEN ≠ { })

a) select minimum cost node n from OPEN and put it in CLOSED


b) for each adjacent node m of n

i) If m is not in OPEN or CLOSED then C(m)←C(n)+C(n,m) and P(m)←n

ii) If m is in OPEN then C(m)←min{c(m),C(n)+C(n,m)}

iii) If C(m) has decreased then P(m)←n

}
A is start vertex , put A in OPEN
Dijkstra’s Algorithm Example
3 OPEN A(0)
4 B
F
A0
1
CLOSED

2 3
5
2
C
Node Parent
10 A
8
B

C
D E
3 D

F
Pick minimum cost node N from OPEN - A(0)
Compute cost of adjacent nodes of B,C and D
Dijkstra’s Algorithm Example of A and put in OPEN is not already present

3 OPEN B(4) C(2) D(5)


4 B4
F
A0
1
CLOSED A(0)

2 3
5
2
C2
Node Parent
10 A
8
B A

C A
D5 E
3 D A

F
Cost of nodes B,C and D updated
Pick minimum cost node N from OPEN - C(2)
Compute cost of adjacent nodes B,D,E and F
Dijkstra’s Algorithm Example of C and put in OPEN is not already present

3 OPEN B(3) D(5) E(12) F(5)


4 B3
F5
A0
1
CLOSED A(0) C(2)

2 3
5
2
C2
Node Parent
10 A
8
B C

E C A
D5
12
3 D A

E C

F C
Cost of nodes B,F and E updated
Pick minimum cost node N from OPEN - B(3)
Compute cost of adjacent nodes F of B and
Dijkstra’s Algorithm Example put in OPEN is not already present

3 OPEN D(5) E(12) F(5)


4 B3
F5
A0
1
CLOSED A(0) C(2) B(3)

2 3
5
2
C2
Node Parent
10 A
8
B C

E C A
D5
12
3 D A

E C

F C
No node updated
Pick minimum cost node N from OPEN - D(5)
Compute cost of adjacent nodes E of D and
Dijkstra’s Algorithm Example put in OPEN is not already present

3 OPEN E(8) F(5)


4 B3
F5
A0
1
CLOSED A(0) C(2) B(3) D(5)

2 3
5
2
C2
Node Parent
10 A
8
B C

C A
D5 E8
3 D A

E D

F C
Cost of nodes E updated
Pick minimum cost node N from OPEN - F(5)
Compute cost of adjacent nodes E of F and
Dijkstra’s Algorithm Example put in OPEN is not already present

3 OPEN E(7)
4 B3
F5
A0
1
CLOSED A(0) C(2) B(3) D(5) F(5)

2 3
5
2
C2
Node Parent
10 A
8
B C

C A
D5 E7
3 D A

E F

F C
Cost of nodes E updated
Pick minimum cost node N from OPEN - E(7)
OPEN empty - Terminate
Dijkstra’s Algorithm Example
3 OPEN
4 B3
F5
A0
1
CLOSED A(0) C(2) B(3) D(5) F(5) E(7)

2 3
5
2
C2
Node Parent
10 A
8
B C

C A
D5 E7
3 D A

E F

F C
Algorithm Terminates
Dijkstra’s Algorithm Path and Routing Table
Node Parent
Node and Parent Table is
A used to construct shortest
path table
B C
Routing Table of Node A
C A Node Path Cost reflects shortest path to
D A A 0 each and every node from
node A
E F B ACB 3
Dest. Next Cost
F C C AC 2 Node

D AD 5 A 0

E ACFE 7 B C 3

F ACF 5 C C 2

D D 5

E C 7

F C 5
Question 6 Explain the following internetworking devices

1. Network Interface Card


2. Modems
3. Repeaters
4. Routers
5. Hubs
6. Bridges
7. Switches
8. Gateways

You might also like