Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_TrafficDistribBestEffort.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_TrafficDistribBestEffort.hpp"
00021 #include "GeneratorTrace.hpp"
00022 #include "Utils.hpp" 
00023 
00024 #include <cmath>
00025 
00026 
00040 int C_TrafficDistribBestEffort::authorize_new_call ()
00041 {
00042   int           L_callLimit;
00043   int           L_burstLimit;
00044   float         L_NB1, L_S1;
00045   float         L_NB2, L_NB3, L_S2;
00046   unsigned long L_outgoingTraffic;
00047   static bool   L_burst = false;
00048 
00049   long L_maxNbCreationPerPeriod ;
00050   long L_desiredAverageRate ;
00051   long L_createdCallNb ;
00052   long L_nbCallCreatedInPeriod ;
00053   
00054   update ();
00055   reset () ;
00056 
00057   m_sem_max->P();
00058   L_maxNbCreationPerPeriod = m_maxNbCreationPerPeriod ;
00059   m_sem_max->V();
00060   m_sem_desired->P();
00061   L_desiredAverageRate = m_desiredAverageRate ;
00062   m_sem_desired->V();
00063   m_sem_created_call->P();
00064   L_createdCallNb = m_createdCallNb ;
00065   m_sem_created_call->V();
00066   m_sem_created_call_period->P();
00067   L_nbCallCreatedInPeriod = m_nbCallCreatedInPeriod ;
00068   m_sem_created_call_period->V();
00069   
00070   
00071   // check m_currentTrafficDuration
00072   if (m_currentTrafficDuration <= ms_setup_time) {
00073     return (0);
00074   }
00075   L_outgoingTraffic = m_currentTrafficDuration - ms_setup_time;
00076 
00077   GEN_DEBUG(0, "Outgoing Traffic Duration (ti-TO): " << (long) L_outgoingTraffic);
00078   GEN_DEBUG(0, "Desired Call Rate (VO)           : " << (long) L_desiredAverageRate);
00079   GEN_DEBUG(0, "Calls Already Created (Ni)       : " << (long) L_createdCallNb);
00080 
00081   L_NB1 = ( (float) ( (float) L_outgoingTraffic / (float) 1000.0) * 
00082             (float) L_desiredAverageRate);
00083 
00084   GEN_DEBUG(0, "NB1 = [ (ti - T0) * V0 ]         : " << L_NB1);
00085 
00086   if ( (float) L_createdCallNb >= L_NB1 ) {
00087     L_callLimit = 0;
00088   } else {
00089     L_S1 = L_NB1 - (float) L_createdCallNb;
00090     L_callLimit = (int) (floor (L_S1) + (fmodf (L_S1, 1.0) > 0 ? 1 : 0));
00091   }
00092    
00093   if (!L_maxNbCreationPerPeriod) {
00094     return (L_callLimit); // no burstLimit
00095   }
00096 
00097   GEN_DEBUG(0, "Current Period Duration (ti-tp)           : " << m_currentPeriodDuration << " ms");
00098   GEN_DEBUG(0, "Max Call Creation per Period (Vp)         : " << L_maxNbCreationPerPeriod);
00099   GEN_DEBUG(0, "Period Duration (D0)                      : " << m_periodDuration << " ms");
00100   GEN_DEBUG(0, "Calls Already Created during Period (Np)  : " << m_nbCallCreatedInPeriod);
00101 
00102   // compute L_burstLimit
00103   L_NB2 = (float) L_nbCallCreatedInPeriod;
00104   //L_NB3 = (((float) m_currentPeriodDuration * (float) m_maxNbCreationPerPeriod) /
00105   // (P1)       ((float) m_periodDuration * (float) 1000.0));
00106 
00107   L_NB3 = (((float) m_currentPeriodDuration * 
00108             (float) L_maxNbCreationPerPeriod) /
00109            ((float) m_periodDuration));
00110 
00111   GEN_DEBUG(0, "NB3 = [ ( (ti - tp) / D0 ) * Vp ] : " << L_NB3);
00112 
00113   if (L_NB2 >= L_NB3) {
00114     L_burstLimit = 0;
00115   } else {
00116     L_S2 = L_NB3 - L_NB2;
00117     L_burstLimit = (int) (floor (L_S2) + (fmodf (L_S2, 1.0) > 0 ? 1 : 0));
00118   }
00119 
00120   GEN_DEBUG(0, "L_burstLimit = " << L_burstLimit);
00121   if (!L_callLimit) {
00122     GEN_DEBUG(0, "End of burst mode : reached expected call rate");
00123     L_burst = false;
00124   } else {
00125     if (!L_burstLimit) {
00126       // L_burstLimit may be null either if burst limit has been reached
00127       // or at the beginning of a new period
00128       if ((!L_burst) && (L_nbCallCreatedInPeriod)) {
00129         GEN_DEBUG(0, "Burst control : reached burst limit");
00130         L_burst = true;
00131       }
00132     }
00133   }
00134   return ((L_callLimit < L_burstLimit) ? L_callLimit : L_burstLimit);
00135 } /* end of authorize_new_call */
00136 
00137 
00138 C_TrafficDistribBestEffort::C_TrafficDistribBestEffort () : C_TrafficModel() { 
00139 }
00140 
00141 
00142 C_TrafficDistribBestEffort::~C_TrafficDistribBestEffort() {
00143 }
00144 

Generated on Wed Mar 7 14:44:58 2007 for Seagull by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002