00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 /* 00003 * Copyright (c) Xerox Corporation 1997. All rights reserved. 00004 * 00005 * This program is free software; you can redistribute it and/or modify it 00006 * under the terms of the GNU General Public License as published by the 00007 * Free Software Foundation; either version 2 of the License, or (at your 00008 * option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, but 00011 * WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 * 00019 * Linking this file statically or dynamically with other modules is making 00020 * a combined work based on this file. Thus, the terms and conditions of 00021 * the GNU General Public License cover the whole combination. 00022 * 00023 * In addition, as a special exception, the copyright holders of this file 00024 * give you permission to combine this file with free software programs or 00025 * libraries that are released under the GNU LGPL and with code included in 00026 * the standard release of ns-2 under the Apache 2.0 license or under 00027 * otherwise-compatible licenses with advertising requirements (or modified 00028 * versions of such code, with unchanged license). You may copy and 00029 * distribute such a system following the terms of the GNU GPL for this 00030 * file and the licenses of the other code concerned, provided that you 00031 * include the source code of that other code when and as the GNU GPL 00032 * requires distribution of source code. 00033 * 00034 * Note that people who make modified versions of this file are not 00035 * obligated to grant this special exception for their modified versions; 00036 * it is their choice whether to do so. The GNU General Public License 00037 * gives permission to release a modified version without this exception; 00038 * this exception also makes it possible to release a modified version 00039 * which carries forward this exception. 00040 */ 00041 #ifndef lint 00042 static const char rcsid[] = 00043 "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/adc/actp-adc.cc,v 1.6 2005/08/26 05:05:27 tomh Exp $"; 00044 #endif 00045 00046 00047 //Acceptance region Tangent at Peak Admission Control 00048 00049 #include "adc.h" 00050 #include <stdlib.h> 00051 #include <math.h> 00052 00053 class ACTP_ADC : public ADC { 00054 public: 00055 ACTP_ADC(); 00056 void teardown_action(int,double,int); 00057 void rej_action(int,double,int); 00058 protected: 00059 int admit_flow(int,double,int); 00060 int rejected_; 00061 double s_; 00062 double sump_; 00063 }; 00064 00065 ACTP_ADC::ACTP_ADC() : rejected_(0), sump_(0) 00066 { 00067 bind("s_", &s_); 00068 type_ = new char[5]; 00069 strcpy(type_, "ACTP"); 00070 } 00071 00072 00073 00074 int ACTP_ADC::admit_flow(int cl,double r,int b) 00075 { 00076 //get peak rate this class of flow 00077 double p=peak_rate(cl,r,b); 00078 00079 if (backoff_) { 00080 if (rejected_) 00081 return 0; 00082 } 00083 00084 //fprintf (stderr,"%f %f %f\n",sump_*(1-exp(-p*s_)),exp(-p*s_)*est_[cl]->avload(),est_[cl]->avload()); 00085 if (sump_*(1-exp(-p*s_))+exp(-p*s_)*est_[cl]->avload() <= bandwidth_) { 00086 sump_+= p; 00087 if (dobump_) { 00088 est_[cl]->change_avload(p); 00089 } 00090 return 1; 00091 } 00092 else { 00093 rejected_=1; 00094 return 0; 00095 } 00096 } 00097 00098 00099 void ACTP_ADC::rej_action(int cl,double r,int b) 00100 { 00101 double p=peak_rate(cl,r,b); 00102 sump_ -= p; 00103 } 00104 00105 00106 void ACTP_ADC::teardown_action(int cl,double r,int b) 00107 { 00108 rejected_=0; 00109 double p=peak_rate(cl,r,b); 00110 sump_ -= p; 00111 } 00112 00113 static class ACTP_ADCClass : public TclClass { 00114 public: 00115 ACTP_ADCClass() : TclClass("ADC/ACTP") {} 00116 TclObject* create(int,const char*const*) { 00117 return (new ACTP_ADC()); 00118 } 00119 }class_actp_adc;
1.4.6