CN File
CN File
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;
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;
int main() {
int nodeCount = 10;
int simulationTime = 1000
simulateTokenBus(nodeCount, simulationTime);
return 0;
}
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);
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
int main() {
sender();
receiver();
return 0;
}
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;
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
int main() {
sender();
receiver();
return 0;
}
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;
int base = 0;
int nextFrameToSend = 0;
int main() {
sender();
receiver();
return 0;
}