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

📄 aggegress-adc.cc.cc

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


/* Implementation of Egress Admission Control */

/* here the measurement parameter is the peak rate and Delay qos requested of the flow . */

#include "adc.h"
#include "aggegress-est.h"
#include "ip.h"
#include "packet.h"
#include "address.h"

struct numofflowinfo
{
   int flowid;
   double starttime;
};
typedef struct numofflowinfo numofflowinfo;

class AggEgress_ADC : public ADC {
public:
        static int flowcount;
        static numofflowinfo flowinfoarray[100];
        static int numofacceptcount;
        static int numofrejectcount;
	AggEgress_ADC();
        static void incrementacceptcount()
        {
           numofacceptcount++;
        }
        static void decrementacceptcount()
        {
           numofacceptcount--;
        }
        static void incrementrejectcount()
        {
           numofrejectcount++;
        }
        static void printnumofflowcount()
        {
          printf(" The number of flows in the network at %d are %d
\n",(int)Scheduler::instance().clock(),numofacceptcount);
        }
   	int command(int argc, const char*const* argv);
protected:
        int admit_flow(int,double,int){}
	int admit_flow(Packet*,Handler*,int,double,int);
	int admit_flow2(int,double,int,int);
        void updateflowarray(int);
        int off_ip_;
	double clr_;
        //double bdutil_;
	double delay_;  /* figure out how to set this */
        double lifetime_;
        double delayrequest_;
        double arrenvelope[17][2];
        double serenvelope[17][2];

};

int AggEgress_ADC::flowcount = 0;
int AggEgress_ADC::numofacceptcount = 0;
int AggEgress_ADC::numofrejectcount = 0;
numofflowinfo AggEgress_ADC::flowinfoarray[100];

static class AggEgress_ADCClass : public TclClass {
public:
	AggEgress_ADCClass() : TclClass("ADC/AggEgress") {}
	TclObject* create(int,const char*const*) {
		return (new AggEgress_ADC());
	}
} class_ae_adc;

AggEgress_ADC::AggEgress_ADC() 
{
	bind("clr_", &clr_);
        //bind("bdutil_",&bdutil_);
        bind("lifetime_",&lifetime_);
        bind("delayrequest_", &delayrequest_);
        bind("off_ip_", &off_ip_);

	/* to accurately set delay_ I need to know the link bandwidth
	 * and the buffer size. bandwidth is known (needed for admission
	 * decisions).  assume this all gets set with call to 'setbuf'.
	 */
	type_ = new char[10];
	strcpy(type_, "AggEgress");
        for(int i = 0;i < 100;i++)
        {
           flowinfoarray[i].flowid = 0;
           flowinfoarray[i].starttime = 0.0;
        }
        
}

void AggEgress_ADC::updateflowarray(int fid)
{
  flowinfoarray[flowcount].flowid = fid;
  flowinfoarray[flowcount++].starttime = (int)Scheduler::instance().clock();
}


int AggEgress_ADC::admit_flow(Packet *p,Handler *h,int cl, double r, int b)
{
	int ret;
        int fid;
        hdr_ip *iph=(hdr_ip*)p->access(off_ip_);
        fid = iph->flowid();
        ret = admit_flow2(cl, r, b,fid);
	printf("Admit_flow %d\n", ret);
        printnumofflowcount();
        printf("\n The number of flows rejected so far are %d \n",numofrejectcount);     
	return(ret);
}

int AggEgress_ADC::admit_flow2(int /* cl */, double r, int b,int fid)
{
   int i;
   int ii;
   double denotemp;
   double numotemp;
   double arrenvelopebar[17];
   double stddeviation[17];
   double alpha = 1.0;
   double firstfactor;
   double secondfactor;
   double lhsfactor;
   int admissionflag;
   double flowendtime;
   double currenttime;
   int returnvalue;

   printf("\n the rate in admit_flow2 is %f \n",r);  
   
   // obtain the envelopes from egress estimator

   arrenvelope = AggEgress_Est::arrivalenvelope;
   serenvelope = AggEgress_Est::serviceenvelope;

   // obtain the square root of the sum of the variances of arrival and service envelopes

   for(i = 0; i < 17;i++)
   {
           stddeviation[i] = sqrt(arrenvelope[i][1] + serenvelope[i][1]);
   }

   // obtain Abar from the arrival envelopes

   for(i = 0;i < 17;i++)
   {
      denotemp = (pow(2,i)*1000*8.0)/(arrenvelope[i][0]);
      denotemp = denotemp + r;
      numotemp = (pow(2,i)*1000*8.0)/denotemp;
      arrenvelopebar[i] = numotemp;
   }

   // Here we are actually performing the check for admission of the new flow
   // The peak rate request by the new flow is r and the Delay request is 20msecs
   // The equation is ........for i ranging from 0 to 16

   // [servicemean(i) + alpha * standarddeviation of service(i)] -
   // [arrivalbarmean(i) - alpha * standarddeviation of arrival(i)] < Delayrequest

   // [servicemean(i) - arrivalbarmean(i)] + alpha*[sqrt(servicevariance(i) +
   // arrivalvariance(i))]

   for(i = 0;i < 17;i++)
   {
      //if((arrenvelope[i][0] != 0 && serenvelope[i][0] != 0)&&(arrenvelope[i][0] < serenvelope[i][0]))
      if(arrenvelope[i][0] != 0 && serenvelope[i][0] != 0)
      {
          firstfactor = serenvelope[i][0] - arrenvelopebar[i];
          secondfactor = alpha * stddeviation[i];
          lhsfactor = firstfactor + secondfactor;
      }
      else
      {
         lhsfactor = 0.0;
      }

      printf("\n the lhsfactor for the row %d -----  is %f \n",i,lhsfactor);
      
      if(lhsfactor < delayrequest_)
      {
        admissionflag = 1;
      }
      else
      {
        admissionflag = 0;
        break;
      }
   }
  
   if(admissionflag == 1)
   {
      updateflowarray(fid);
      currenttime = (int)Scheduler::instance().clock();
      for(ii = 0;ii < flowcount;ii++)
      {
         flowendtime = flowinfoarray[ii].starttime + lifetime_;
         if(currenttime == flowendtime)
         {
            AggEgress_ADC::decrementacceptcount();
         }
      }

      AggEgress_ADC::incrementacceptcount();
      returnvalue = 1;
   }
   else
   {
      currenttime = (int)Scheduler::instance().clock();
      for(ii = 0;ii < flowcount;ii++)
      {
         flowendtime = flowinfoarray[ii].starttime + lifetime_;
         if(currenttime == flowendtime)
         {
            AggEgress_ADC::decrementacceptcount();
         }
      }

      AggEgress_ADC::incrementrejectcount();
      returnvalue = 0;
   }
return(returnvalue);

}

int AggEgress_ADC::command(int argc, const char*const* argv)
{
	if (argc == 3) {
		if (strcmp(argv[1], "setbuf") == 0) {
			double b;
			b = atof(argv[2]);
			/* convert buffer size to delay */
			delay_ = b/bandwidth_;
			return(TCL_OK);
		}
	}
	return (ADC::command(argc, argv));
}

⌨️ 快捷键说明

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