Sie sind auf Seite 1von 8

Leaky Bucket Algorithm

Programming Guidelines This section guides the user to link his/her own code for Leaky Bucket Algorithm to NetSim. Pre - Conditions The user program should read the inputted scenario from text file named Input with extension txt. The user program after executing the concept should write the required output to a file named Output with extension txt. The path of the input file and the output file can be viewed on clicking the Button Path in NetSim. General Program Flow The program begins with the Reading of the Inputs from the input file Input.txt. Executing the required concept and, The results of the program should be written into the output file Output.txt. File Format Input File Input.txt file contains three lines of data. The data format in the input file is as follows: Input rate at 1st second >Input rate at 2nd second>..>Input rate at 10th second> Buffer Size> Output rate> The data is stored in the file with a delimiter > in between. Sample File data 200>200>200>200>200>200>200>200>200>200> 100> 100> Code to read the Input File The C code to read the input file for Leaky Bucket Algorithm is given below as function fnReadInput().

Output File Output.txt file contains three lines of data. The data format in the output file should be as follows: Output rate at 1st second >Output rate at 2nd second>..> Discard rate at 1st second >Discard rate at 2nd second>..>

Total number of seconds taken > The data should be stored in the file with a delimiter > in between. Sample File data 100>100>100>100>100>100>100>100>100>100>100> 0>100>100>100>100>100>100>100>100>100>0> 11> Code to read the Output File The C code on how to write the output file for Leaky Bucket Algorithm is given below as function fnWriteOutput().

Source Code Skeleton Here a skeleton code written in C is given using this the user can write only the Leaky bucket algorithm inside the function fnLBA() using the variables already declared. #include <stdio.h> #include <conio.h> #include <string.h> #include <stdlib.h>

//#include "Variable.h" int nInputRate[10]; int nBufferSize = 0; // To store the Input rate per second for 10 Seconds // To store the Total Buffer capacity

int nOutputRate = 0; // To store the Output capacity int nOutputRates[30]; int nBufferLevel[30]; int nDiscardRate[30]; // To store the number of packets discarded due to buffer full per second for 10 Seconds int nSeconds = 0; // To store the total time taken to transmit

char* szApp_path=NULL; char* szInput_path=NULL; char* szOutput_path=NULL;

//#include "Function.h" void fnReadInput() { char szString[80]; file char* pszToken; seperated from token int nLoop = 0; // Loop counter // Character string to store the string // Character string to store the string from the input

FILE *fpInput; /* Open the Input file input.txt.

//Input File pointer

This has the inputs given from the front end front end. The input.txt file is present in the Application path where the NETSIM is installed. The path of the input.txt is specified in the V.B. Steps for getting the path 1. Click the Methodology button. 2. In the left hand side of the screen there are two file paths specified 3. The first one has the filename Input.txt(The file that has the user inputs)

4. The second one has the filename Output.txt (The file in which the user has to write his outputs) Note: The naming of the input and the output file must be same as the text displayed in the Methodology screen.

Consider the Application is Installed in sc:\\netsim */

szInput_path=(char*)malloc(200*sizeof(char)); strcpy(szInput_path,szApp_path); strcat(szInput_path,"\\Input.txt"); fpInput = fopen(szInput_path,"r+"); // Opening the input file in read mode

fgets(szString,60,fpInput); local variable

// The first line of the input file is read to a

///szToken = (char*)malloc(31); pszToken = strtok(szString,">"); token while( pszToken != NULL ) // Traversing to the ned of the string { // The string is seperated from the

nInputRate[nLoop]=atoi(pszToken); // The Input rate at different seconds is stored in a local array nLoop++; pszToken = strtok( NULL, ">" ); }

fgets(szString,10,fpInput); local variable

// The second line of the input file is read to a

pszToken=strtok(szString,">"); nBufferSize = atoi(pszToken); local variable pszToken=strtok(NULL,">"); // The Buffer capacity is stored in a

fgets(szString,10,fpInput); local variable

// The Third line of the input file is read to a

pszToken=strtok(szString,">"); nOutputRate = atoi(pszToken); stored in a local variable pszToken=strtok(NULL,">"); // The Output rate per second is

fclose(fpInput); }

// Closing the Input file

void fnWriteOutput() { FILE *fpOutput;

int nLoop,nInterval; /* Open the Input file input.txt. This has the inputs that you have made in the front end. The input.txt file is present in the Application path where the NETSIM is installed. The path of the input.txt is specified in the V.B. Steps for getting the path 1. Click the Methodology button. 2. In the left hand side of the screen there are two file paths specified 3. The first one has the filename Input.txt(The file that has the user inputs) 4. The second one has the filename Output.txt (The file in which the user has to write his outputs) Note: The naming of the input and the output file must be same as the text displayed in the Methodology screen.

Consider the Application is Installed in c:\\netsim */ szOutput_path=(char *)malloc(200 * sizeof(char)); strcpy(szOutput_path,szApp_path); strcat(szOutput_path,"\\Output.txt");

fpOutput = fopen(szOutput_path,"w");

for( nLoop = 1;nLoop <= nSeconds;nLoop++) { fprintf(fpOutput,"%d>",nOutputRates[nLoop-1]); }

fprintf(fpOutput,"\n");

for(nLoop = 1;nLoop <= nSeconds;nLoop++) { fprintf(fpOutput,"%d>",nDiscardRate[nLoop-1]); } fprintf(fpOutput,"\n%d>",nSeconds); fprintf(fpOutput,"\n");

fclose(fpOutput);

for (nInterval = 0; nInterval < 30;nInterval ++) // initialising the storage array value { nDiscardRate [nInterval ] = 0;

nOutputRates [nInterval ] = 0; nBufferLevel [nInterval ] = 0; } }

void fnLBA(); int main(int argc,char* argv[]) {

// Executes the Leaky Bucket Algorithm

szApp_path=(char*)malloc(200*sizeof(char)); strcpy(szApp_path,argv[1]);

fnReadInput(); fnLBA(); fnWriteOutput(); return 0; } void fnLBA() { // Write you own code for Leaky Bucket algorithm HERE. }

Das könnte Ihnen auch gefallen