C_TrafficDistribPoisson.cpp

00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  *
00016  * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
00017  *
00018  */
00019 
00020 #include "C_TrafficDistribPoisson.hpp"
00021 #include "GeneratorTrace.hpp"
00022 #include "GeneratorError.h"
00023 #include "Utils.hpp" 
00024 
00025 #include <cmath>
00026 
00027 #include "randomc.h"                   // define classes for random number generators
00028 #define RANDOM_GENERATOR TRandomMersenne // define which random number generator to use
00029 #include "stocc.h"
00030 
00031 // implementation of virtual function of the AgnerLib
00032 void FatalError(char * ErrorText) {
00033   GEN_FATAL(E_GEN_FATAL_ERROR,"Error in AgnerLib Poisson distribution: " << ErrorText);
00034 }
00035 
00036 C_TrafficDistribPoisson::C_TrafficDistribPoisson () : C_TrafficModel() { 
00037 
00038   int L_seed;
00039 
00040   m_LastFctCallTS = 0;
00041 
00042   L_seed = time(0); 
00043   NEW_VAR(m_sto, StochasticLib1(L_seed));
00044 
00045 }
00046 
00047 
00048 C_TrafficDistribPoisson::~C_TrafficDistribPoisson() {
00049 }
00050 
00051 
00052 
00053 int C_TrafficDistribPoisson::authorize_new_call ()
00054 {
00055   long L_desiredAverageRate ;
00056 
00057   float L_poissonMean;
00058   float L_poissonVal = 0.0;
00059   long  L_DeltaSinceLastFuncCall;   // ms
00060 
00061   reset ();
00062   update ();
00063 
00064   m_sem_desired->P();
00065   L_desiredAverageRate = m_desiredAverageRate ;
00066   m_sem_desired->V();
00067 
00068   if (m_currentTrafficDuration <= ms_setup_time) {
00069     return (0);
00070   }
00071 
00072   L_DeltaSinceLastFuncCall = m_currentTrafficDuration - m_LastFctCallTS;
00073 //  L_DeltaSinceLastFuncCall = m_currentPeriodDuration ;
00074   L_poissonMean =( (float)  ( (float) L_DeltaSinceLastFuncCall / (float) 1000.0)  *
00075      (float) L_desiredAverageRate);
00076   L_poissonVal = m_sto->Poisson(L_poissonMean);
00077   
00078   m_LastFctCallTS = m_currentTrafficDuration;
00079 
00080   return ((int) L_poissonVal);
00081 
00082 } /* end of authorize_new_call */
00083 
00084 

Generated on Wed Mar 7 14:57:54 2007 for Seagull by  doxygen 1.4.6