timewindow-est.cc

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) Xerox Corporation 1997. All rights reserved.
00003  *
00004  * This program is free software; you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License as published by the
00006  * Free Software Foundation; either version 2 of the License, or (at your
00007  * option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License along
00015  * with this program; if not, write to the Free Software Foundation, Inc.,
00016  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  * Linking this file statically or dynamically with other modules is making
00019  * a combined work based on this file.  Thus, the terms and conditions of
00020  * the GNU General Public License cover the whole combination.
00021  *
00022  * In addition, as a special exception, the copyright holders of this file
00023  * give you permission to combine this file with free software programs or
00024  * libraries that are released under the GNU LGPL and with code included in
00025  * the standard release of ns-2 under the Apache 2.0 license or under
00026  * otherwise-compatible licenses with advertising requirements (or modified
00027  * versions of such code, with unchanged license).  You may copy and
00028  * distribute such a system following the terms of the GNU GPL for this
00029  * file and the licenses of the other code concerned, provided that you
00030  * include the source code of that other code when and as the GNU GPL
00031  * requires distribution of source code.
00032  *
00033  * Note that people who make modified versions of this file are not
00034  * obligated to grant this special exception for their modified versions;
00035  * it is their choice whether to do so.  The GNU General Public License
00036  * gives permission to release a modified version without this exception;
00037  * this exception also makes it possible to release a modified version
00038  * which carries forward this exception.
00039  */
00040 #ifndef lint
00041 static const char rcsid[] =
00042     "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/adc/timewindow-est.cc,v 1.7 2005/08/26 05:05:28 tomh Exp $";
00043 #endif
00044 
00045 
00046 //Time Window estimation
00047 
00048 #include "estimator.h"
00049 #include <stdlib.h>
00050 
00051 class TimeWindow_Est : public Estimator {
00052 public:
00053     TimeWindow_Est() :scnt(1),maxp(0){bind("T_",&T_);};
00054     inline void change_avload(double incr) { avload_ += incr; if (incr >0) scnt=0;}
00055 protected:
00056     void estimate();
00057     int scnt;
00058     double maxp;//maximum of previous interval
00059     int T_;
00060 };
00061 
00062 void TimeWindow_Est::estimate() {
00063     measload_ = meas_mod_->bitcnt()/period_;
00064     if (meas_mod_->bitcnt()/period_ >avload_)
00065         avload_=meas_mod_->bitcnt()/period_;
00066     if (maxp < meas_mod_->bitcnt()/period_)
00067         maxp=meas_mod_->bitcnt()/period_;
00068 
00069     if (scnt == T_)  
00070         {
00071             scnt-=T_;
00072             avload_=maxp;
00073             maxp=0;
00074         }
00075     //printf("%f %f %f\n",Scheduler::instance().clock(),avload_,meas_mod_->bitcnt()/period_);
00076     
00077     fflush(stdout);
00078     meas_mod_->resetbitcnt();
00079     scnt++;
00080 }
00081 
00082 static class TimeWindow_EstClass : public TclClass {
00083 public:
00084     TimeWindow_EstClass() : TclClass ("Est/TimeWindow") {}
00085     TclObject* create(int,const char*const*) {
00086         return (new TimeWindow_Est());
00087     }
00088 }class_timewindow_est;
00089 

Generated on Tue Mar 6 16:47:52 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6