Sunday, 24 March 2013

CN2 LEAKY BUCKET PROGRAM


#include<stdio.h>
#include<stdlib.h>
#define MIN(x,y) (x>y)? y:x
int main()
{

    int orate, drop=0,cap,x,count=0,inp[10]={0},i=0,nsec,ch;
    printf("\n enter the bucket size");
    scanf("%d",&cap);
    printf("\n enter the output rate");
    scanf("%d",&orate);
    do
    {
        printf("\n enter the number of packets coming at second %d",i+1);
        scanf("%d",&inp[i]);
        i++;
        printf("\n press 1 to continue or 0 to exit------");
        scanf("%d",&ch);
        }
         while(ch);
         nsec=i;
        printf("\n sec\t rec\t sent\t drop\t rem\n");
        for(i=0;count||i<nsec;i++)
       {
        printf("%d",i+1);
        printf("\t %d\t",inp[i]);
        printf("%d\t", MIN((inp[i]+count),orate));
        if((x=inp[i]+count-orate)>0)
        {
           if(x>cap)
           {
             count=cap;
            drop=x-cap;
            }
            else
            count=x;
            drop=0;
            }
        else
        {
        drop=0;
        count=0;
        }
        printf("%d\t %d\n",drop,count);
    }
    }
    


No comments:

Post a Comment