Write run a program in C/C++ to simulate the behavior of Aloha random access protocol and
show the output.
You are required to the following tasks:
• Generate packets randomly
• Simulate transfer of packets at a random time
• Simulate the occurrence of collision of packets
• Calculate throughput of Aloha
• Plot throughput Vs Load graph
SOLUTION
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout<<"Enter the system bps: ";
double bps;
cin>>bps;
cout<<"Enter the system packet length in bits: ";
double packet_length;
cin>>packet_length;
//Now lets calculate the packet rate
double packet_rate = bps/packet_length;
//Now lets calculate the maximum throughput for the ALOHA
double max_ALOHA_throughput = packet_rate * 0.184;
//Now lets calculate the maximum throughput for the slotted ALOHA
double max_slotted_ALOHA_throughput = packet_rate * 0.368;
cout<<"The system is operating at "<<bps<<"bps"<<endl;
cout<<"The packets are "<<packet_length<<" bits long"<<endl;
cout<<"The packet rate is : "<<packet_rate<<endl;
cout<<"The maximum throughput for the ALOHA is : "<<max_ALOHA_throughput<<" packets/second"<<endl;
cout<<"The maximum throughput for the slotted ALOHA is : "<<max_slotted_ALOHA_throughput<<" packets/second"<<endl;
return 0;
}
Comments
Leave a comment