NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <iostream>
#include <time.h> // clocks per second

using namespace std;
void main() {
while (1) {
clock_t ticks;
ticks=1; // number of ticks is fixed 15 --> so i start with 1 end with 15
int choise;
cout<< "Please Select your option 1.The leaky bucket 2.The token bucket: ";
cin>>choise;
// for both algortihms packets have fixed size , queue is infinite ,number of ticks is fixed 15
if(choise==1){ // leaky bucket

int arrival_rate; // number of packets arrived at each tick
int maximum_arrival_rate=30; // maximum number of arriving packets at each tick
int departure_rate=5; // number of departing packets at each tick
int queue=0;
cout<<endl;
while(ticks!=16)
{arrival_rate=rand()% 30; // random number of arriving packets between 0 and maximum_arrival_rate(30)
queue+=arrival_rate;
cout<<ticks<<endl;
cout<<"number of arrived packets is "<<arrival_rate<<endl;
if(queue<departure_rate)
{cout<<"number of departured packets is "<<queue<<endl;
queue=0;}
else { // if queue > or = from departue rate
cout<<"number of departured packets is "<<departure_rate<<endl;
queue-=departure_rate;
}

cout<<"number of packets in the queue is "<<queue<<endl;
++ticks;}
continue;
}
else
if(choise==2) { // token bucket

int token_rate=2; // number of added tokens at each tick
int bucket_capacity=30; // maximum number of tokens in the bucket
int arrival_rate; //number of arriving packets
int maximum_arrival_rate=20; // maximum number of arriving packets at each tick
int c=0; //number of tokens in the bucket
int buffer=0; // initialize queue

while(ticks!=16)
{arrival_rate=rand()%20; // random number of arriving packets between 0 and maximum arrival_rate(20)
buffer +=arrival_rate; // puts arrival packets in the queue
cout<<ticks<<endl;
c+= token_rate;
if(c>30) c=30;
cout<<"number of arrived packets is "<<arrival_rate<<endl;
if(c>=buffer)
{cout<<"number of departured packets is "<<buffer<<endl;
buffer=0;
c-=buffer;
cout<<"number of packets in the queue is "<<buffer<<endl;
}
if(c<buffer)
{cout<<"number of departed packets is "<<c<<endl;
buffer-=c;
c=0;
cout<<"number of packets in the queue is "<<buffer<<endl;
}
++ticks;}
continue;




}
else
{cout << "Error Option Try again"<<endl;
continue;
}

} // end of while



}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.