⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aggegress-est.cc.cc

📁 在网络的边缘路由器中并不能完全接受所到的包
💻 CC
字号:

#include "aggegress-est.h"

double AggEgress_Est::tempmeandelay = 0.0;
double AggEgress_Est::tempmaxdelay = 0.0;
int AggEgress_Est::outsideboundcount = 0;
int AggEgress_Est::tempcount = 0;

double AggEgress_Est::arrivalenvelope[17][2];
double AggEgress_Est::serviceenvelope[17][2];

//creating a circular list for storing the maxarrivaltime and minservicetime for every second
//for the last 10seconds

struct maxmintimelist
{
  double maxminarrayoftime[17][2];
  maxmintimelist* next;
};
typedef struct maxmintimelist maxmintimelist;

maxmintimelist *headoflist,*tailoflist,*navigatelist,*nodeoflist;

AggEgress_Est::AggEgress_Est() {

	/* assume period_, T_ and M_ get set in Tcl */
        bind("lifetimeofflow_", &lifetimeofflow_);
        bind("simulationtime_", &simulationtime_);
        bind("delayrequest_", &delayrequest_);
	bind("T_", &T_);
	bind("M_", &M_);
}

void AggEgress_Est::createmaxmintimelist(double a[][2])
{
    nodeoflist = (maxmintimelist*)malloc(sizeof(maxmintimelist));
    for(int i = 0;i < 17;i++)
    {
       nodeoflist->maxminarrayoftime[i][0] = a[i][0];
       nodeoflist->maxminarrayoftime[i][1] = a[i][1];
    }
    nodeoflist->next = NULL;
    
    headoflist = headoflist->next;
    free(tailoflist->next);
    tailoflist->next = nodeoflist;
    tailoflist = tailoflist->next;
    tailoflist->next = headoflist;

}

void AggEgress_Est::initializemaxminlist(void)
{
  int p;
  int q;
  headoflist = NULL;
  tailoflist = NULL;
  navigatelist = NULL;
  nodeoflist = NULL;
  for(p = 0;p < 10;p++)
  {
      nodeoflist = (maxmintimelist*)malloc(sizeof(maxmintimelist));
      for(q = 0;q < 17;q++)
      {
         nodeoflist->maxminarrayoftime[q][0] = 0.0;
         nodeoflist->maxminarrayoftime[q][1] = 0.0;
      }   
      nodeoflist->next = NULL;
        
      if(headoflist==NULL)
      {
         headoflist = nodeoflist;
         tailoflist = nodeoflist;
         navigatelist = nodeoflist;
      }
      else
      {
         navigatelist->next = nodeoflist;
         navigatelist = navigatelist->next;
         tailoflist = navigatelist;
      }
  }
  tailoflist->next = headoflist;
}       
  
void AggEgress_Est::printmaxmintimelist(void)
{
   navigatelist = headoflist;
   int j = 0;
   int i;
   while (navigatelist->next != headoflist)
   {
      printf("The list for table %d is ------------------- \n",j);
      for(i = 0; i < 17; i++)
      {
        printf(" Row %d --------- arrivaltime %f         servicetime %f\n",i,navigatelist->maxminarrayoftime[i][0],navigatelist->maxminarrayoftime[i][1]); 
      }
      navigatelist = navigatelist->next;
      j++;
   }
   
   if(navigatelist->next == headoflist)
   {
      printf("The list for table %d is ------------------- \n",j);
      for(i = 0; i < 17; i++)
      {
        printf(" Row %d --------- arrivaltime %f         servicetime %f\n",i,navigatelist->maxminarrayoftime[i][0],navigatelist->maxminarrayoftime[i][1]);
       }
    }
}

void AggEgress_Est::computemeanmaxdelay(void)
{
    temp = Trace::measure;
    int count = Trace::snoopqueuecount;
    int i;
    double computedelay;

    for(i=0;i <= count;i++)
    {
       computedelay = temp[i].getservicetime() - temp[i].getarrivaltime();
       tempmeandelay = tempmeandelay + computedelay;
       if(tempmaxdelay < computedelay)
       {
          tempmaxdelay = computedelay;
       }
       if(computedelay > delayrequest_)
       {
          outsideboundcount++;
       }
    }
    tempcount = tempcount + count;
}
    
        
 
void AggEgress_Est::extractarrivalservicetimesintoarray()
{
     temp = Trace::measure;

     // extracting the arrival and service times for the packets into an array for computing  

     int count = Trace::snoopqueuecount;

     printf("\n The number of packets which arrived in the 1sec interval are %d \n",count);
 
     int i;

     for(i=0;i <= count;i++)
     {
       arrayoftimes[i][0] = temp[i].getarrivaltime();
       arrayoftimes[i][1] = temp[i].getservicetime();
     }

     for(i = count+1;i < NUMOFPACKS;i++)
     {
       arrayoftimes[i][0] = 0.0;
       arrayoftimes[i][1] = 0.0;
     }
 
   // for(i = 0;i <= count;i++)
   // {
   //   printf(" row %d ------ arrivaltime = %f    servicetime = %f\n",i,arrayoftimes[i][0],arrayoftimes[i][1]);
   // }

     // end of extracting
}

void AggEgress_Est::computationofminarrivalmaxservicetimes()
{ 
   int i;
   int p;
   int j;
   int k;
   int flag;
   double minarrivaltime;
   double maxservicetime;

   //--------- computation of minimum arrival time ------------
 
   p = 0;
   j = 0; 
   while(p < 17)
   {
      // The variable j keeps track of how many packets to consider....i.e 1k,2k,4k....
      j = (int)pow(2,p);
      minarrivaltime = 9999;
      for(i = 0; i < NUMOFPACKS-j; i++)
      {
         if(arrayoftimes[i+j][0] == 0.0)
         {
             break;
         }
         temparrivaltime = arrayoftimes[i+j][0] - arrayoftimes[i][0];
         if(minarrivaltime > temparrivaltime)
         {
            minarrivaltime = temparrivaltime;
         }
      }
      maxmintimes[p][0] = minarrivaltime;
      p++;
    }

    // ---------- end of computation of minimum arrival time -------

    //----------- computation of maximum service time -------------

    p = 0;
    j = 0;
    
    while(p < 17)
    {
       //printf("\n in side the while loop the value of p is %d \n",p);

       j = (int)pow(2,p) - 1;
       maxservicetime = 0.0;

       // this for loop is to extract the max servicetime for packets
       // of size 2 to the power p

       for(i = 0; i < NUMOFPACKS - j; i++)
       {
          if(arrayoftimes[i+j][1] == 0)
          {
             break;
          }
          k = j;
          flag = 0;

          tempservicetime = arrayoftimes[i+k][1] - arrayoftimes[i][0];

          //this tempservicetime should be considered only if there is
          //backlog in the network for (pow(2,p) - 1) packets

          while(k != 0)
          {
             if(arrayoftimes[i+k][0] < arrayoftimes[i+k-1][1])
             {
                flag = 1;
             }
             else
             {
                flag = 0;
                break; 
             }
             k--;
          }//end of the while for k

          if(j == 0)
          {   
            flag = 1;
          }   
          if(flag == 1)  
          {
             if(maxservicetime < tempservicetime)
             {   
                maxservicetime = tempservicetime;
             }
          }
       }//end of the for loop for i
           
       maxmintimes[p][1] = maxservicetime;
       p++;
   }//end of the while for p

  //------------ end of computation --------------------

}

void AggEgress_Est::generatearrivalenvelope()
{
  int j=0;
  double tempmean;
  double tempmeancount;
  double tempvariance;
  double tempvariancecount;
  double mean;
  double variance;

  //The arrival envelope is stored in the array arrivalenvelope 
  //The first column gives the mean and the second column the variance
  
  while(j < 17)
  {
     navigatelist = headoflist;
     tempmean = 0.0;
     tempmeancount = 0;
     while(navigatelist->next != headoflist)
     {
        if(navigatelist->maxminarrayoftime[j][0] != 0 && navigatelist->maxminarrayoftime[j][0] != 9999)
        {
           tempmeancount++;
           tempmean = tempmean + navigatelist->maxminarrayoftime[j][0];
        }
        navigatelist = navigatelist->next;
     }

     if(navigatelist->next == headoflist)
     {
        if(navigatelist->maxminarrayoftime[j][0] != 0 && navigatelist->maxminarrayoftime[j][0] != 9999)
        {
           tempmeancount++;
           tempmean = tempmean + navigatelist->maxminarrayoftime[j][0];
        }
     }

     if(tempmeancount > 0)
     {
        mean = tempmean/tempmeancount;
     }
     else
     {
        mean = 0.0;
     }
     arrivalenvelope[j][0] = mean;

     navigatelist = headoflist;
     tempvariance = 0.0;
     tempvariancecount = 0;

     while(navigatelist->next != headoflist)
     {
        if(navigatelist->maxminarrayoftime[j][0] != 0 && navigatelist->maxminarrayoftime[j][0] != 9999)
        {
           tempvariancecount++;
           tempvariance = tempvariance + ((mean - navigatelist->maxminarrayoftime[j][0])*(mean -navigatelist->maxminarrayoftime[j][0]));
        }
        navigatelist = navigatelist->next;
     }
 
     if(navigatelist->next == headoflist)
     {
        if(navigatelist->maxminarrayoftime[j][0] != 0 && navigatelist->maxminarrayoftime[j][0] != 9999)
        {
          tempvariancecount++;
          tempvariance = tempvariance + ((mean - navigatelist->maxminarrayoftime[j][0])*(mean - navigatelist->maxminarrayoftime[j][0]));
        }
     }
     
     if(tempvariancecount > 1)
     {
        variance = tempvariance / (tempvariancecount-1);
     }
     else
     {
        variance = 0.0;
     }
     arrivalenvelope[j][1] = variance;
    
     j++;
  }

  printf("\n The arrival envelopes are : \n");
  for(j = 0; j < 17; j++)
  {
    printf(" Row %d --------- Mean is %f ..... Variance is %f \n",j,arrivalenvelope[j][0],arrivalenvelope[j][1]);
  }
}
 
void AggEgress_Est::generateserviceenvelope()
{
  int j=0;
  double tempmean;
  double tempmeancount;
  double tempvariance;
  double tempvariancecount;
  double mean;
  double variance;

  //The service envelope is stored in the array service envelope
  //The first column gives the mean and the second column the variance
  
  while(j < 17)
  {
     navigatelist = headoflist;
     tempmean = 0.0;
     tempmeancount = 0;
     while(navigatelist->next != headoflist)
     {
        if(navigatelist->maxminarrayoftime[j][1] != 9999 && navigatelist->maxminarrayoftime[j][1] != 0)
        {
           tempmeancount++;
           tempmean = tempmean + navigatelist->maxminarrayoftime[j][1];
        }
        navigatelist = navigatelist->next;
     }

     if(navigatelist->next == headoflist)
     {
        if(navigatelist->maxminarrayoftime[j][1] != 9999 && navigatelist->maxminarrayoftime[j][1] != 0)
        {
           tempmeancount++;
           tempmean = tempmean + navigatelist->maxminarrayoftime[j][1];
        }
     }

     if(tempmeancount > 0)
     {
        mean = tempmean/tempmeancount;
     }
     else
     {
        mean = 0.0;
     }
     serviceenvelope[j][0] = mean;

     navigatelist = headoflist;
     tempvariance = 0.0;
     tempvariancecount = 0;

     while(navigatelist->next != headoflist)
     {
        if(navigatelist->maxminarrayoftime[j][1] != 9999 && navigatelist->maxminarrayoftime[j][1] != 0)
        {
           tempvariancecount++;
           tempvariance = tempvariance + ((mean - navigatelist->maxminarrayoftime[j][1])*(mean -navigatelist->maxminarrayoftime[j][1]));
        }
        navigatelist = navigatelist->next;
     }
 
     if(navigatelist->next == headoflist)
     {
        if(navigatelist->maxminarrayoftime[j][1] != 9999 && navigatelist->maxminarrayoftime[j][1] != 0)
        {
          tempvariancecount++;
          tempvariance = tempvariance + ((mean - navigatelist->maxminarrayoftime[j][1])*(mean - navigatelist->maxminarrayoftime[j][1]));
        }
     }
     
     if(tempvariancecount > 1)
     {
        variance = tempvariance / (tempvariancecount-1);
     }
     else
     {
        variance = 0.0;
     }
     serviceenvelope[j][1] = variance;
    
     j++;
  }

  printf("\n The service envelopes are : \n");
  for(j = 0; j < 17; j++)
  {
    printf(" Row %d --------- Mean is %f ..... Variance is %f \n",j,serviceenvelope[j][0],serviceenvelope[j][1]);
  }

}  
   

void AggEgress_Est::estimate() 
{
     static int check = 0;
     double meandelay;
     double maxdelay;
     double outsidebound;


     if(check == 0)
     {

        double now2 = Scheduler::instance().clock();
        printf("\n the time in estimate function is %f \n",now2); 

        // This part of the code is for extracting the arrival and service times of the 
        // packets into an array

        extractarrivalservicetimesintoarray();      

        // this part of the code is used for generating the table which contains the
        // maximum arrival time and minimum service time for 1k, 2k, 4k...... 64k

        computationofminarrivalmaxservicetimes();     
  
       // This part of the code is for creating the circular list which keeps data over a 
       // time period of 10 seconds

        createmaxmintimelist(maxmintimes);
       // printmaxmintimelist();

       // This part of the code is for generating the arrival and service envelopes
       
       // The arrival envelope contains the mean and variance of all the arrival times
          generatearrivalenvelope();

       // The service envelope contains the mean and variance of all the service times
          generateserviceenvelope();

          if(now2 > (lifetimeofflow_ + 80.0))
          {
             computemeanmaxdelay();
          }
         
          if(now2 == (simulationtime_ - 1))
          {
             meandelay = tempmeandelay/tempcount;
             maxdelay = tempmaxdelay;
             outsidebound = (double)outsideboundcount/tempcount;
             printf("\n The meandelay is %f \n",meandelay);
             printf("\n The maxdelay is %f \n",maxdelay);
             printf("\n The outsidebound is %f \n",outsidebound);
          }

         Trace::snoopqueueinitialize();
         Trace::setsnoopqueuecount();

     }

     if(check == 0)
     {
        check = 1;
     }
     else
     {
        check = 0;
     }


}

void AggEgress_Est::start() {

	printf("AggTrafEnv_Est::start\n");
        initializemaxminlist();
        //printmaxmintimelist();
	est_timer_.resched(period_);

}

static class AggEgress_EstClass : public TclClass {
public:
	AggEgress_EstClass() : TclClass("Est/AggEgress") {}
	TclObject* create(int, const char*const*) {
		return (new AggEgress_Est());
	}
} class_aggegress_est;


		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -