You are on page 1of 5

JSS ACADEMY OF TECHNICAL EDUCATION

JSS Campus, Dr.Vishnuvardhan Road, Bengaluru-560060

DEPARTMENT OF ELECTRONICS AND


COMMUNICATION ENGINEERING

COMPUTER NETWORK SYSTEM (18EC72)


ACTIVITY REPORT
ON

“CSMA/CA”
Submitted in the partial fulfilment of the requirements
for the award of the degree of

BACHELOR OF ENGINEERING
IN
ELECTRONICS AND COMMUNICATION
ENGINEERING
For the Academic Year 2023-2024
Submitted by

SL NO NAME USN SIGNATURE


1 1JS20EC047 NAKUL C
2 1JS20EC048 NAVYA MAHESH NAIK
3 1JS20EC049 NAYANA H S
4 1JS20EC050 NEHA K

SUBMIT
TED TO MS
GUNASAG
ARI G S
Q.Implement and analyze CSMA/CA using simulation tool.

• PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define CHANNEL_IDLE 0
#define CHANNEL_BUSY 1
#define TRANSMISSION_PROBABILITY 0.5

// Simulate whether the channel is idle based on a probability


int isChannelIdle()
{
return ((double)rand() / RAND_MAX) < TRANSMISSION_PROBABILITY ?
CHANNEL_BUSY : CHANNEL_IDLE;
}

// CSMA/CA algorithm
void csma_ca(int nodeID) {
printf("Node %d wants to transmit.\n", nodeID);

while (1)
{
if (isChannelIdle() == CHANNEL_IDLE)
{
printf("Channel is idle. Transmitting...\n");
break;
}
else
{
printf("Channel is busy. Waiting...\n");
}
}

printf("Transmission complete for Node %d.\n", nodeID);


}

int main()
{
// Seed for random number generation
srand(time(NULL));

// Number of nodes in the network


int numNodes = 5;

// Simulate CSMA/CA for each node


for (int i = 0; i < numNodes; i++) {
csma_ca(i + 1);
}

return 0;
}

Output :
C program for CSMA/CA that addresses the hidden station problem

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>

#define NUM_STATIONS 3

// Function to simulate CSMA/CA with hidden station problem


bool csma_ca_hidden_station(int station_id) {
// Simulate channel busy/idle
bool channel_busy = rand() % 2 == 1;

if (!channel_busy) {
printf("Station %d senses idle channel, starts transmission...\n", station_id);
return true;
} else {
printf("Station %d senses busy channel, defers transmission...\n", station_id);
return false;
}
}

int main() {
srand(time(NULL));

// Simulate CSMA/CA for each station


for (int i = 0; i < NUM_STATIONS; ++i) {
if (csma_ca_hidden_station(i + 1)) {
printf("Transmission successful for Station %d\n", i + 1);
} else {
printf("Transmission deferred for Station %d\n", i + 1);
}
printf("\n");
}

return 0;
}
Output:

You might also like