Professional Documents
Culture Documents
A2345916002
B.tech. CSE-EVE, semester-6
Data Communication and Computer Networks
Assignment 6
1. Algorithms
1.1 Pure ALOHA protocol:
● In pure ALOHA, the stations transmit frames whenever they have data to send.
● When two or more stations transmit simultaneously, there is collision and the frames are
destroyed.
● In pure ALOHA, whenever any station transmits a frame, it expects the acknowledgement
from the receiver.
● If acknowledgement is not received within specified time, the station assumes that the frame
(or acknowledgement) has been destroyed.
● If the frame is destroyed because of collision the station waits for a random amount of time
and sends it again. This waiting time must be random otherwise same frames will collide
again and again.
● Slotted ALOHA was invented to improve the efficiency of pure ALOHA as chances of
collision in pure ALOHA are very high.
● In slotted ALOHA, the time of the shared channel is divided into discrete intervals called
slots.
● The stations can send a frame only at the beginning of the slot and only one frame is sent in
each slot.
●
● In slotted ALOHA, if any station is not able to place the frame onto the channel at the
beginning of the slot i.e. it misses the time slot then the station has to wait until the
beginning of the next time slot.
● In slotted ALOHA, there is still a possibility of collision if two stations try to send at the
beginning of the same time slot
2. Examples:
3. C implementation
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <dos.h>
main()
{
float S1, S2, G, J, val[100];
int I, n, K, delay;
void wait();
clrscr();
printf("Please Give the Total Load : ");
scanf("%d", &n);
printf("Please Enter the value of load \n");
for (I=0; I<n; I++)
{
scanf("%f", &val[I]);
}
clrscr();
printf("\nOUTPUT 1: (THROUGHPUT Vs LOADCURVE)\n\n");
printf("s=g*exp(-G) FOR SLOTTED ALOHA * \n");
printf("s=g*exp(-2G) FOR PURE ALPHA #\n");
printf("\n------ (THROUGHPUT PER FRAME TIME)----\n");
for(K=0; K<n; K++)
{
G=val[K];
S1 = G * exp (-G);
S2 = G * exp(-2 * G);
printf("%1.3f", G );
for (I=0; I <=S1*20; I++)
{
printf(" ");
}
printf("*");
for(I=S2*20; I<=S2*75; I++ )
{
printf(" ");
}
printf("#\n");
}
printf("G (ATTEMPTS PER PACKET TIME) \n\n");
wait();
getch();
clrscr();
printf("\nOUTPUT 2 (DELAY Vs THROUGHPUT) \n\n");
printf("\n-----(THOUGHPUT PER FRAME TIME)----\n");
for(K=0; K<n; K++)
{
G=val[K];
S1 = G * exp (-G);
printf("3");
for (I=0; I <=S1*2.7; I++)
{
printf(" ");
}
printf("*\n");
}
printf("\n");
printf("---- DELAY -----");
wait();
getch();
clrscr();
}
void wait()
{
sound(440);
delay(300);
nosound();
}
Output:
3.2 Slotted ALOHA Protocol:
Program:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define ROW 25
#define COL 70
#define N 3
int main()
{
float p;
char grid [ROW][COL];
int count, ff1 = 0, ff2 =0, ff3=0;
rand();
printf(" The Slotted ALOHA Simulation\n\n");
printf(" This program simluates one instance of slotted ALOHA.\n");
printf(" There are 3 nodes, each with one packet to transmit.\n");
printf(" The user imputs the probability of transmission\n");
printf(" which is the same for all three nodes.\n");
printf(" After a node has sucessfully transmitted its one packet\n");
printf(" it will stop transmission and wait for the other nodes\n");
printf(" to transmit its one packet\n\n");
igrid(grid);
printgrid(grid);
for (count=1; count<10; count++)
move (grid, count, &ff1,&ff2, &ff3,p);
void move (char grid[][COL], int count1, int *ff1,int *ff2, int*ff3, float p1)
{
float prob;
int j, f1 = 0, f2 = 0, f3 = 0,
n1 = 0, n2 =0 , n3= 0, newp=0;
prob = p1 * 100;
newp = ceil(prob);
n1 = rand();
n2 = rand();
n3 = rand();
if (f1==1)
for (j = 1; j<6; j++){
grid [6][j+1+(7* count1)] = '*';
grid [7][j+1+(7* count1)] = '*';
grid [8][j+1+(7* count1)] = '*';
}
if (f2==2)
for (j = 1; j<6; j++){
grid [11][j+1+(7* count1)] = '*';
grid [12][j+1+(7* count1)] = '*';
grid [13][j+1+(7* count1)] = '*';
}
if (f3==3)
for (j = 1; j<6; j++){
grid [16][j+1+(7* count1)] = '*';
grid [17][j+1+(7* count1)] = '*';
grid [18][j+1+(7* count1)] = '*';
}
if (f1==0 &&
f2==0 && f3==3){
*ff3 = 1;
grid
[22][3 + (7*count1)] =
'S';
}
if (f1==0 &&
f2==0 && f3==0)
grid
[22][3 + (7*count1)] =
'E';
if (f1==0 &&
f2==2 && f3==3)
grid
[22][3 + (7*count1)] =
'C';
if (f1==1 &&
f2==0 && f3==3)
grid
[22][3 + (7*count1)] =
'C';
if (f1==1 &&
f2==2 && f3==0)
grid
[22][3 + (7*count1)] =
'C';
if (f1==1 &&
f2==2 && f3==3)
grid
[22][3 + (7*count1)] =
'C';
printgrid(grid);
}
Output: