Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

asim.h

Go to the documentation of this file.
00001 // Copyright (c) 2000 by the University of Southern California
00002 // All rights reserved.
00003 //
00004 // Permission to use, copy, modify, and distribute this software and its
00005 // documentation in source and binary forms for non-commercial purposes
00006 // and without fee is hereby granted, provided that the above copyright
00007 // notice appear in all copies and that both the copyright notice and
00008 // this permission notice appear in supporting documentation. and that
00009 // any documentation, advertising materials, and other materials related
00010 // to such distribution and use acknowledge that the software was
00011 // developed by the University of Southern California, Information
00012 // Sciences Institute.  The name of the University may not be used to
00013 // endorse or promote products derived from this software without
00014 // specific prior written permission.
00015 //
00016 // THE UNIVERSITY OF SOUTHERN CALIFORNIA makes no representations about
00017 // the suitability of this software for any purpose.  THIS SOFTWARE IS
00018 // PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
00019 // INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00020 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 //
00022 // Other copyrights might apply to parts of this software and are so
00023 // noted when applicable.
00024 
00025 
00026 #ifndef _RED_ROUTER_H_
00027 #define _RED_ROUTER_H_
00028 
00029 #include <assert.h>
00030 #include <stdio.h>
00031 #include <math.h>
00032 
00033 
00034 class RedRouter {
00035   double MinTh, MaxTh, MaxP;
00036   double Lambda_L;
00037   double Lambda_H;
00038 
00039   void Populate();
00040  public:
00041   RedRouter(int mTh, int MTh, double MP) {
00042     MinTh = mTh;
00043     MaxTh = MTh;
00044     MaxP = MP; 
00045     Populate();
00046   }
00047   double ComputeProbability(double Lambda, double &Delay);
00048   short Identical(int mTh, int MTh, double MP) {
00049     return (mTh == MinTh &&
00050             MTh == MaxTh &&
00051             MP  == MaxP);
00052   }
00053 };
00054 
00055 void RedRouter::Populate() {
00056   // rho = Lambda_L: p = 0 => rho/(1-rho) = MinTh
00057   Lambda_L = ((double)MinTh)/((double)(1+MinTh));
00058 
00059   // rho = Lambda_H: p = Max_p => rho(1-Max_p)/(1-rho(1-Max_p)) = MaxTh;
00060   if (MaxP < 1)
00061     Lambda_H = ((double)MaxTh)/((double)(1+MaxTh))/(1-MaxP);
00062 }
00063 
00064 
00065 double RedRouter::ComputeProbability(double Lambda, double &delay) {
00066   double p;
00067   
00068   if (Lambda <= Lambda_L) {
00069     delay = Lambda/(1-Lambda);
00070     return 0;
00071   }
00072 
00073   if (MaxP < 1 && Lambda > Lambda_H) {
00074     delay = MaxTh;
00075     p = (Lambda - Lambda_H*(1 - MaxP))/Lambda;
00076     return p;
00077   }
00078 
00079   // Solve the quadratic a.p^2 + b.p + c = 0
00080   double a, b, c;
00081   a = Lambda * (MaxTh - MinTh)/(MaxP);
00082   b = (MaxTh - MinTh)*(1-Lambda)/MaxP + MinTh * Lambda + Lambda;
00083   c = MinTh*(1-Lambda)-Lambda;
00084 
00085   p = (-b + sqrt(b*b - 4 * a * c))/(2 * a);
00086   delay = Lambda*(1-p)/(1-(Lambda*(1-p)));
00087   return p;
00088 }
00089 
00090 
00091 #endif
00092 
00093 
00094 
00095 
00096 
00097 

Generated on Tue Apr 20 12:14:11 2004 for NS2.26SourcesOriginal by doxygen 1.3.3