0% found this document useful (0 votes)
43 views8 pages

CN File

The document discusses the implementation and simulation of various network protocols. It covers 6 topics: 1) Simulating the CSMA/CD protocol and measuring its performance under different parameters. 2) Simulating token bus and token ring protocols to analyze throughput and latency. 3) Implementing error detection using checksums to verify error-free transmission. 4) Simulating a 1-bit sliding window stop-and-wait protocol between a sender and receiver. 5) Implementing the Go-Back-N protocol using a sliding window and cumulative acknowledgments. 6) Simulating the selective repeat protocol with individual acknowledgments and retransmissions of timed-out frames. Pseudocode

Uploaded by

Ajay Kumar
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)
43 views8 pages

CN File

The document discusses the implementation and simulation of various network protocols. It covers 6 topics: 1) Simulating the CSMA/CD protocol and measuring its performance under different parameters. 2) Simulating token bus and token ring protocols to analyze throughput and latency. 3) Implementing error detection using checksums to verify error-free transmission. 4) Simulating a 1-bit sliding window stop-and-wait protocol between a sender and receiver. 5) Implementing the Go-Back-N protocol using a sliding window and cumulative acknowledgments. 6) Simulating the selective repeat protocol with individual acknowledgments and retransmissions of timed-out frames. Pseudocode

Uploaded by

Ajay Kumar
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/ 8

Topic 1: Performance Study of CSMA/CD Protocol through Simulation

Algorithm:
1. Initialize the network environment and configure the nodes.
2. Set the simulation parameters such as node density, traffic load, and network conditions.
3. Begin the simulation:
a. For each node, check the channel for any ongoing transmission (Carrier Sense).
b. If the channel is idle, the node transmits the frame.
c. Monitor the channel for collisions during transmission (Collision Detection).
d. If a collision occurs, the node waits for a random backoff period before retransmitting.
e. Measure the throughput, latency, and collision rate during the simulation.
4. Analyze the simulation results and calculate performance metrics.
5. Repeat the simulation with different parameters and configurations to observe their impact
on performance.

Code (C++):
#include <iostream>
#include <random>
void simulateCSMACD(int nodeCount, int simulationTime) {
std::random_device rd;
std::default_random_engine generator(rd());
std::uniform_real_distribution<double> distribution(0.0, 1.0);

int collisions = 0;
int successfulTransmissions = 0;

for (int time = 0; time < simulationTime; time++) {


bool channelBusy = (distribution(generator) < 0.2

for (int node = 0; node < nodeCount; node++) {


if (!channelBusy) {
successfulTransmissions++;
bool collisionDetected = (distribution(generator) < 0.1); // Assuming 10%
probability of collision
if (collisionDetected) {
collisions++;
}
}
}
}
double throughput = successfulTransmissions / (double)simulationTime;
double collisionRate = collisions / (double)successfulTransmissions;
std::cout << "Simulation Results:\n";
std::cout << "Successful Transmissions: " << successfulTransmissions << std::endl;
std::cout << "Collision Rate: " << collisionRate << std::endl;
std::cout << "Throughput: " << throughput << std::endl;
}
int main() {
int nodeCount = 10;
int simulationTime = 1000;

simulateCSMACD(nodeCount, simulationTime);

return 0;
}

Topic 2: Performance Study of Token Bus and Token Ring Protocols through
Simulation

Algorithm:
1. Initialize the network topology and configure nodes for the desired protocol (Token Bus or
Token Ring).
2. Set simulation parameters such as node density, traffic load, and network conditions.
3. Begin the simulation:
a. Simulate token circulation in the network according to the protocol's rules.
b. Nodes transmit data only when they possess the token.
c. Measure the throughput, latency, and network utilization during the simulation.
4. Analyze the simulation results and calculate performance metrics.
5. Repeat the simulation with different parameters and configurations to observe their impact
on performance.

Code (C++):
#include <iostream>
#include <vector>
void simulateTokenBus(int nodeCount, int simulationTime) {
std::vector<bool> tokens(nodeCount, true); // Initialize tokens for each node
int successfulTransmissions = 0;

for (int time = 0; time < simulationTime; time++) {


for (int node = 0; node < nodeCount; node++) {
if (tokens[node]) {
successfulTransmissions++;
}
tokens[node] = false; // Pass the token to the next node
}
}
double throughput = successfulTransmissions / (double)simulationTime;
std::cout << "Simulation Results:\n";
std::cout << "Successful Transmissions: " << successfulTransmissions << std::endl;
std::cout << "Throughput: " << throughput << std::endl;
}

int main() {
int nodeCount = 10;
int simulationTime = 1000

simulateTokenBus(nodeCount, simulationTime);

return 0;
}

Topic 3: Implementation of Error Detection and Correction Algorithms

Algorithm (Checksum):
1. Take input data to be transmitted.
2. Calculate the checksum by summing all the data bytes.
3. Append the checksum to the data.
4. Transmit the data with the checksum.
5. On the receiver side, extract the received data and checksum.
6. Calculate the checksum of the received data.
7. Compare the calculated checksum with the received checksum.
8. If they match, the data is error-free. Otherwise, an error occurred during transmission.

Code (C++):
#include <iostream>
#include <vector>
int calculateChecksum(const std::vector<int>& data) {
int sum = 0;
for (int byte : data) {
sum += byte;
}
return sum;
}
bool detectErrorsWithChecksum(const std::vector<int>& data, int checksum) {
int calculatedChecksum = calculateChecksum(data);
return (calculatedChecksum == checksum);
}

int main() {
std::vector<int> data = { 1, 2, 3, 4, 5 };
int checksum = calculateChecksum(data);

std::cout << "Data: ";


for (int byte : data) {
std::cout << byte << " ";
}
std::cout << std::endl;

std::cout << "Checksum: " << checksum << std::endl;


bool isErrorDetected = detectErrorsWithChecksum(data, checksum);

if (isErrorDetected) {
std::cout << "Error detected during transmission." << std::endl;
} else {
std::cout << "No errors detected during transmission." << std::endl;
}

return 0;
}

Topic 4: Implementation and Study of 1-Bit Sliding Window (Stop and Wait) Protocol

Algorithm:
1. Initialize the sender and receiver.
2. Sender:
a. Read data to be transmitted.
b. Send a frame with the data to the receiver.
c. Start a timer to wait for an acknowledgment.
d. If the acknowledgment is received within the timeout period, move to the next frame.
e. If the acknowledgment is not received within the timeout period, retransmit the frame.
f. Repeat steps b to e until all frames are transmitted.
3. Receiver:
a. Receive a frame from the sender.
b. Send an acknowledgment back to the sender.
c. Process the received data.
d. Repeat steps a to c for each frame received.

Code (C++):
#include <iostream>
void sender() {
int frameCount = 5; // Number of frames to transmit

for (int frame = 0; frame < frameCount; frame++) {


std::cout << "Sending Frame " << frame << std::endl;
bool isAcknowledged = false;
while (!isAcknowledged) {
// Start timer
// Wait for acknowledgment
// If acknowledgment received, set isAcknowledged to true
}
}
}
void receiver() {
int frameCount = 5; // Number of frames expected
for (int frame = 0; frame < frameCount; frame++) {
// Receive frame from the sender

// Send acknowledgment back to the sender


std::cout << "Sending Acknowledgment for Frame " << frame << std::endl;

// Process received data


}
}

int main() {
sender();
receiver();

return 0;
}

Topic 5: Implementation and Study of Go-Back-N Protocol

Algorithm:
1. Initialize the sender and receiver.
2. Sender:
a. Divide the data into fixed-size frames.
b. Send multiple frames, one after another, without waiting for individual
acknowledgments.
c. Maintain a sliding window to keep track of sent frames and acknowledgments received.
d. Start a timer for the first frame in the window.
e. If an acknowledgment is received within the timeout period, move the window forward.
f. If a timeout occurs, retransmit all frames in the window.
g. Repeat steps b to f until all frames are transmitted.
3. Receiver:
a. Receive frames from the sender.
b. Send cumulative acknowledgments for received frames.
c. Process the received data.
d. Repeat steps a to c for each frame received.

Code (C++):
#include <iostream>
#include <vector>
void sender() {
int frameCount = 10;
int windowSize = 4;

std::vector<bool> acknowledgments(frameCount, false);

int nextFrameToSend = 0;
int base = 0;
while (base < frameCount) {
for (int i = base; i < base + windowSize && i < frameCount; i++) {
std::cout << "Sending Frame " << i << std::endl;
}
for (int i = base; i < base + windowSize && i < frameCount; i++) {
// Start timer for the frame

// Wait for acknowledgment

// If acknowledgment received, mark it


acknowledgments[i] = true;
}
while (base < frameCount && acknowledgments[base]) {
base++;
}
}
}
void receiver() {
int frameCount = 10; // Number of frames expected

for (int i = 0; i < frameCount; i++) {


// Receive frame from the sender

// Send acknowledgment back to the sender


std::cout << "Sending Acknowledgment for Frame " << i << std::endl;

// Process received data


}
}

int main() {
sender();
receiver();

return 0;
}

Topic 6: Implementation and Study of Selective Repeat Protocol

Algorithm:
1. Initialize the sender and receiver.
2. Sender:
a. Divide the data into fixed-size frames.
b. Send multiple frames, one after another, without waiting for individual
acknowledgments.
c. Maintain a sending window to keep track of sent frames and acknowledgments
received.
d. Start a timer for each frame in the window.
e. If an acknowledgment is received within the timeout period, mark the frame as
acknowledged.
f. If a timeout occurs for a specific frame, retransmit only that frame.
g. Repeat steps b to f until all frames are transmitted.
3. Receiver:
a. Receive frames from the sender.
b. Send individual acknowledgments for received frames.
c. Process the received data.
d. Repeat steps a to c for each frame received.

Code (C++):
#include <iostream>
#include <vector>
void sender() {
int frameCount = 10;
int windowSize = 4;

std::vector<bool> acknowledgments(frameCount, false);

int base = 0;
int nextFrameToSend = 0;

while (base < frameCount) {


for (int i = base; i < base + windowSize && i < frameCount; i++) {
std::cout << "Sending Frame " << i << std::endl;
}
for (int i = base; i < base + windowSize && i < frameCount; i++) {
// Start timer for the frame

// Wait for acknowledgment

// If acknowledgment received, mark it


acknowledgments[i] = true;
}
while (base < frameCount && acknowledgments[base]) {
base++;
}
}
}

// Receiver implementation for Selective Repeat protocol


void receiver() {
int frameCount = 10; // Number of frames expected

for (int i = 0; i < frameCount; i++) {


// Receive frame from the sender
// Send acknowledgment back to the sender
std::cout << "Sending Acknowledgment for Frame " << i << std::endl;

// Process received data


}
}

int main() {
sender();
receiver();

return 0;
}

You might also like