00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef lint
00043 static const char rcsid[] =
00044 "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/adc/param-adc.cc,v 1.4 2005/08/26 05:05:27 tomh Exp $";
00045 #endif
00046
00047
00048
00049
00050
00051
00052 #include "adc.h"
00053 #include <stdlib.h>
00054
00055 class Param_ADC : public ADC {
00056 public:
00057 Param_ADC();
00058 void teardown_action(int,double,int);
00059 void rej_action(int,double,int);
00060 void trace(TracedVar* v);
00061 protected:
00062 int admit_flow(int,double,int);
00063 double utilization_;
00064 TracedDouble resv_rate_;
00065 double oresv_rate_;
00066 };
00067
00068 Param_ADC::Param_ADC() : resv_rate_(0), oresv_rate_(0)
00069 {
00070 bind("utilization_",&utilization_);
00071 type_ = new char[5];
00072 strcpy(type_, "PBAC");
00073
00074 resv_rate_.tracer(this);
00075 resv_rate_.name("\"Reserved Rate\"");
00076 }
00077
00078 void Param_ADC::rej_action(int ,double p,int )
00079 {
00080 resv_rate_-=p;
00081 }
00082
00083
00084 void Param_ADC::teardown_action(int ,double p,int )
00085 {
00086 resv_rate_-=p;
00087 }
00088
00089 int Param_ADC::admit_flow(int ,double r,int )
00090 {
00091 if (resv_rate_ + r <= utilization_ * bandwidth_) {
00092 resv_rate_ +=r;
00093 return 1;
00094 }
00095 return 0;
00096 }
00097
00098 static class Param_ADCClass : public TclClass {
00099 public:
00100 Param_ADCClass() : TclClass("ADC/Param") {}
00101 TclObject* create(int,const char*const*) {
00102 return (new Param_ADC());
00103 }
00104 }class_param_adc;
00105
00106 void Param_ADC::trace(TracedVar* v)
00107 {
00108 char wrk[500];
00109 double *p, newval;
00110
00111
00112 if (strcmp(v->name(), "\"Reserved Rate\"") == 0) {
00113 p = &oresv_rate_;
00114 }
00115 else {
00116 fprintf(stderr, "PBAC: unknown trace var %s\n", v->name());
00117 return;
00118 }
00119
00120 newval = double(*((TracedDouble*)v));
00121
00122 if (tchan_) {
00123 int n;
00124 double t = Scheduler::instance().clock();
00125
00126 sprintf(wrk, "f -t %g -s %d -a %s:%d-%d -T v -n %s -v %g -o %g",
00127 t, src_, type_, src_, dst_, v->name(), newval, *p);
00128 n = strlen(wrk);
00129 wrk[n] = '\n';
00130 wrk[n+1] = 0;
00131 (void)Tcl_Write(tchan_, wrk, n+1);
00132
00133 }
00134
00135 *p = newval;
00136
00137 return;
00138
00139
00140
00141 }
00142