packmime_ranvar.h
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:13k
源码类别:

通讯编程

开发平台:

Visual C++

  1. /* 
  2.  * Copyright 2002, Statistics Research, Bell Labs, Lucent Technologies and
  3.  * The University of North Carolina at Chapel Hill
  4.  * 
  5.  * Redistribution and use in source and binary forms, with or without 
  6.  * modification, are permitted provided that the following conditions are met:
  7.  * 
  8.  *    1. Redistributions of source code must retain the above copyright 
  9.  * notice, this list of conditions and the following disclaimer.
  10.  *    2. Redistributions in binary form must reproduce the above copyright 
  11.  * notice, this list of conditions and the following disclaimer in the 
  12.  * documentation and/or other materials provided with the distribution.
  13.  *    3. The name of the author may not be used to endorse or promote 
  14.  * products derived from this software without specific prior written 
  15.  * permission.
  16.  * 
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
  19.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
  20.  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 
  21.  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  22.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  23.  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
  24.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  25.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
  26.  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
  27.  * POSSIBILITY OF SUCH DAMAGE.
  28.  */
  29. /*
  30.  * Reference
  31.  *     Stochastic Models for Generating Synthetic HTTP Source Traffic 
  32.  *     J. Cao, W.S. Cleveland, Y. Gao, K. Jeffay, F.D. Smith, and M.C. Weigle 
  33.  *     IEEE INFOCOM 2004.
  34.  *
  35.  * Documentation available at http://dirt.cs.unc.edu/packmime/
  36.  * 
  37.  * Contacts: Michele Weigle (mcweigle@cs.unc.edu),
  38.  *           Kevin Jeffay (jeffay@cs.unc.edu)
  39.  */
  40. #ifndef ns_pm_ranvar_h
  41. #define ns_pm_ranvar_h
  42. #include "ranvar.h"
  43. #define PACKMIME_XMIT_CLIENT 0
  44. #define PACKMIME_XMIT_SERVER 1
  45. #define PACKMIME_REQ_SIZE 0
  46. #define PACKMIME_RSP_SIZE 1
  47. struct arima_params {
  48.   double d;
  49.   int N;
  50.   double varRatioParam0, varRatioParam1;
  51.   int pAR, qMA;
  52. };
  53. /*:::::::::::::::::::::::::::::::: FX  :::::::::::::::::::::::::::::::::::::*/
  54. // FX generator based on interpolation
  55. class FX {
  56. public:
  57.   FX(const double* x, const double* y, int n);
  58.   ~FX();
  59.   double LinearInterpolate(double xnew);
  60. private:
  61.   double* x_, *y_;
  62.   int nsteps_;
  63.   double* slope_; // avoid real-time slope computation
  64. };
  65. /*:::::::::::::::::::::::::::: Fractional ARIMA  :::::::::::::::::::::::::::*/
  66. class FARIMA {
  67. public:
  68.   FARIMA(RNG* rng, double d, int N, int pAR=0, int qMA=1);
  69.   ~FARIMA();
  70.   double Next();
  71. private:
  72.   RNG* rng_;
  73.   int t_, N_, pAR_, qMA_, tmod_;
  74.   double* AR_, *MA_, *x_, *y_, *phi_, d_;
  75.   double NextLow();
  76. };
  77. /*:::::::::::::::::::::: PackMimeHTTP Transmission Delay RanVar ::::::::::::*/
  78. class PackMimeHTTPXmitRandomVariable : public RandomVariable {
  79. public:
  80.   virtual double value();
  81.   virtual double avg();
  82.   PackMimeHTTPXmitRandomVariable();
  83.   PackMimeHTTPXmitRandomVariable(double rate, int type);
  84.   PackMimeHTTPXmitRandomVariable(double rate, int type, RNG* rng);
  85.   ~PackMimeHTTPXmitRandomVariable();
  86.   double* ratep() {return &rate_;}
  87.   double rate() {return rate_;}
  88.   void setrate(double r) {rate_ = r;}
  89.   int* typep() {return &type_;}
  90.   int type() {return type_;}
  91.   void settype(int t) {type_ = t;}
  92. private:
  93.   void initialize();
  94.   double rate_;
  95.   int type_;
  96.   double varRatio_, sigmaNoise_, sigmaEpsilon_;
  97.   double const_;
  98.   double mean_;
  99.   FARIMA* fARIMA_;
  100.   static const double SHORT_RTT_INVCDF_X[];
  101.   static const double SHORT_RTT_INVCDF_Y[];
  102.   static const double LONG_RTT_INVCDF_X[];
  103.   static const double LONG_RTT_INVCDF_Y[];
  104.   static struct arima_params rtt_arima_params[]; 
  105.   static FX rtt_invcdf[2];
  106.   static const double WEIBULL_SHAPE[2];
  107. };
  108. /*:::::::::::::::::::::: PackMimeHTTP Flow Arrival RanVar :::::::::::::::::*/
  109. class PackMimeHTTPFlowArriveRandomVariable : public RandomVariable {
  110. public:
  111.   virtual double value();
  112.   virtual double avg();
  113.   virtual double avg(int gap_type_);
  114.   PackMimeHTTPFlowArriveRandomVariable();
  115.   PackMimeHTTPFlowArriveRandomVariable(double rate);
  116.   PackMimeHTTPFlowArriveRandomVariable(double rate, RNG* rng);
  117.   ~PackMimeHTTPFlowArriveRandomVariable();
  118.   double* ratep() {return &rate_;}
  119.   double rate() {return rate_;}
  120.   void setrate(double r) {rate_ = r;}
  121. private:
  122.   void initialize();
  123.   double rate_;
  124.   double const_;
  125.   double mean_;
  126.   double varRatio_, sigmaNoise_, sigmaEpsilon_, weibullShape_, weibullScale_;
  127.   FARIMA *fARIMA_;
  128.   static struct arima_params flowarrive_arima_params;
  129. };
  130. /*:::::::::::::::::::::: PackMimeHTTP File Size RanVar :::::::::::::::::::::*/
  131. class PackMimeHTTPFileSizeRandomVariable : public RandomVariable {
  132. public:
  133.   virtual double value();
  134.   virtual double avg();
  135.   PackMimeHTTPFileSizeRandomVariable();
  136.   PackMimeHTTPFileSizeRandomVariable(double rate, int type);  
  137.   PackMimeHTTPFileSizeRandomVariable(double rate, int type, RNG* rng);  
  138.   ~PackMimeHTTPFileSizeRandomVariable(); 
  139.   double* ratep() {return &rate_;}
  140.   double rate() {return rate_;}
  141.   void setrate(double r) {rate_ = r;}
  142.   int* typep() {return &type_;}
  143.   int type() {return type_;}
  144.   void settype(int t) {type_ = t;}
  145. private:
  146.   void initialize();
  147.   double rate_;
  148.   int type_;
  149.   double const_;
  150.   double mean_;
  151.   double varRatio_, sigmaNoise_, sigmaEpsilon_;
  152.   FARIMA* fARIMA_;
  153.   int runlen_, state_;
  154.   double shape_[2], scale_[2];
  155.   double loc_;
  156.   double scale2_;
  157.   int rfsize0(int state);
  158.   int qfsize1(double p);
  159.   /* fitted inverse cdf curves for file sizes  */
  160.   static const double FSIZE0_INVCDF_A_X[];
  161.   static const double FSIZE0_INVCDF_A_Y[];
  162.   static const double FSIZE0_INVCDF_B_X[];
  163.   static const double FSIZE0_INVCDF_B_Y[];
  164.   static const double FSIZE1_INVCDF_A_X[];
  165.   static const double FSIZE1_INVCDF_A_Y[];
  166.   static const double FSIZE1_INVCDF_B_X[];
  167.   static const double FSIZE1_INVCDF_B_Y[];
  168.   static const double FSIZE1_PROB_A;
  169.   static const double FSIZE1_D;
  170.   static const double FSIZE1_VARRATIO_INTERCEPT;
  171.   static const double FSIZE1_VARRATIO_SLOPE;
  172.   /* server file size run length for downloaded and cache validation */
  173.   static const double WEIBULLSCALECACHERUN;
  174.   static const double WEIBULLSHAPECACHERUN_ASYMPTOE;
  175.   static const double WEIBULLSHAPECACHERUN_PARA1;
  176.   static const double WEIBULLSHAPECACHERUN_PARA2;
  177.   static const double WEIBULLSHAPECACHERUN_PARA3;
  178.   static const double WEIBULLSCALEDOWNLOADRUN;
  179.   static const double WEIBULLSHAPEDOWNLOADRUN;
  180.   static const double FSIZE0_PARA[];
  181.   static struct arima_params filesize_arima_params;
  182.   static const double* P;
  183.   static FX fsize_invcdf[2][2]; 
  184.   /* cut off of file size for cache validation */
  185.   static const int FSIZE0_CACHE_CUTOFF; 
  186.   static const int FSIZE0_STRETCH_THRES;
  187.   /* mean of log2(fsize0) for non cache validation flows */
  188.   static const double M_FSIZE0_NOTCACHE;
  189.   /* variance of log2(fsize0) for non cache validation flows */ 
  190.   static const double V_FSIZE0_NOTCACHE; 
  191.   /* fsize0 for non-cache validation flow */
  192.   static const double M_LOC;        /* mean of location */
  193.   static const double V_LOC;        /* variance of location */
  194.   static const double SHAPE_SCALE2; /* Gamma shape parameter of scale^2*/
  195.   static const double RATE_SCALE2;  /* Gamma rate parameter of scale^2 */
  196.   static const double V_ERROR;      /* variance of error */
  197. };
  198. /*:::::::::::::::::::::: PackMimeHTTP Persistent Rsp Size RanVar :::::::::::*/
  199. class PackMimeHTTPPersistRspSizeRandomVariable : public RandomVariable {
  200. public:
  201.   virtual double value();
  202.   virtual double avg();
  203.   PackMimeHTTPPersistRspSizeRandomVariable();
  204.   PackMimeHTTPPersistRspSizeRandomVariable(RNG* rng);
  205.   ~PackMimeHTTPPersistRspSizeRandomVariable(); 
  206.   inline void reset_loc_scale() {loc_ = -1; scale_ = -1;}
  207.   /* cut off of file size for cache validation */
  208.   static const int FSIZE_CACHE_CUTOFF; 
  209. private:
  210.   double loc_;
  211.   double scale_;
  212.   /* fsize for non-cache validation flow */
  213.   static const double M_LOC;        /* mean of location */
  214.   static const double V_LOC;        /* variance of location */
  215.   static const double SHAPE_SCALE2; /* Gamma shape parameter of scale^2*/
  216.   static const double RATE_SCALE2;  /* Gamma rate parameter of scale^2 */
  217.   static const double V_ERROR;      /* variance of error */
  218. };
  219. /*:::::::::::::::::::::: PackMimeHTTP Persistent RanVar ::::::::::::::::::::*/
  220. class PackMimeHTTPPersistentRandomVariable : public RandomVariable {
  221. public:
  222.   virtual double value();
  223.   virtual double avg() {return 0;}
  224.   PackMimeHTTPPersistentRandomVariable();
  225.   PackMimeHTTPPersistentRandomVariable(double prob);  
  226.   PackMimeHTTPPersistentRandomVariable(double prob, RNG* rng);  
  227.   static const double P_PERSISTENT;   /* P(persistent=1) */
  228. private:
  229.   double probability_;    // probability that the connection is persistent
  230. };
  231. /*:::::::::::::::::::::: PackMimeHTTP NumPages RanVar ::::::::::::::::::::::*/
  232. class PackMimeHTTPNumPagesRandomVariable : public RandomVariable {
  233. public:
  234.   virtual double value();
  235.   virtual double avg() {return 0;}
  236.   PackMimeHTTPNumPagesRandomVariable();
  237.   PackMimeHTTPNumPagesRandomVariable(double prob, double shape, double scale);
  238.   PackMimeHTTPNumPagesRandomVariable(double prob, double shape, double scale, 
  239.      RNG* rng);  
  240.   static const double P_1PAGE;       /* P(num reqs=1) */
  241.   static const double SHAPE_NPAGE;   /* shape param for (#page reqs-1)*/
  242.   static const double SCALE_NPAGE;   /* scale param for (#page reqs-1) */
  243. private:
  244.   double probability_;  // probability that the connection has just one page
  245.   double shape_;        // shape of Weibull for number of pages in connection
  246.   double scale_;        // scale of Weibull for number of pages in connection
  247. };
  248. /*:::::::::::::::::::::: PackMimeHTTP SingleObj RanVar :::::::::::::::::::::*/
  249. class PackMimeHTTPSingleObjRandomVariable : public RandomVariable {
  250. public:
  251.   virtual double value();
  252.   virtual double avg() {return 0;}
  253.   PackMimeHTTPSingleObjRandomVariable();
  254.   PackMimeHTTPSingleObjRandomVariable(double prob);
  255.   PackMimeHTTPSingleObjRandomVariable(double prob, RNG* rng);  
  256.   static const double P_1TRANSFER; /* P(#xfers=1 | #page req>=2) */
  257. private:
  258.   double probability_;    // probability that the num of objs is 1
  259. };
  260. /*:::::::::::::::::::::: PackMimeHTTP ObjsPerPage RanVar :::::::::::::::::::*/
  261. class PackMimeHTTPObjsPerPageRandomVariable : public RandomVariable {
  262. public:
  263.   virtual double value();
  264.   virtual double avg() {return 0;}
  265.   PackMimeHTTPObjsPerPageRandomVariable();
  266.   PackMimeHTTPObjsPerPageRandomVariable(double shape, double scale);
  267.   PackMimeHTTPObjsPerPageRandomVariable(double shape, double scale, RNG* rng);
  268.   static const double SHAPE_NTRANSFER; /* shape param for (#xfers-1)*/
  269.   static const double SCALE_NTRANSFER; /* scale param for (#xfers-1) 1.578 */
  270. private:
  271.   double shape_;          // shape of Weibull for number of objs in page
  272.   double scale_;          // scale of Weibull for number of objs in page
  273. };
  274. /*:::::::::::::::::::::: PackMimeHTTP TimeBtwnPages RanVar :::::::::::::::::*/
  275. class PackMimeHTTPTimeBtwnPagesRandomVariable : public RandomVariable {
  276. public:
  277.   virtual double value();
  278.   virtual double avg() {return 0;}
  279.   PackMimeHTTPTimeBtwnPagesRandomVariable();
  280.   PackMimeHTTPTimeBtwnPagesRandomVariable(RNG* rng);
  281.   /* time gap between page requests */
  282.   static const double M_LOC_B;        /* mean of location */
  283.   static const double V_LOC_B;        /* variance of location */
  284.   static const double SHAPE_SCALE2_B; /* Gamma shape param of scale^2*/
  285.   static const double RATE_SCALE2_B;  /* Gamma rate param of scale^2 */
  286.   static const double V_ERROR_B;      /* variance of error */
  287. private:
  288.   double loc_b_;
  289.   double scale2_b_;
  290. };
  291. /*:::::::::::::::::::::: PackMimeHTTP TimeBtwnObjs RanVar ::::::::::::::::::*/
  292. class PackMimeHTTPTimeBtwnObjsRandomVariable : public RandomVariable {
  293. public:
  294.   virtual double value();
  295.   virtual double avg() {return 0;}
  296.   PackMimeHTTPTimeBtwnObjsRandomVariable();
  297.   PackMimeHTTPTimeBtwnObjsRandomVariable(RNG* rng);
  298.   /* time gap within page requests */
  299.   static const double M_LOC_W;        /* mean of location */
  300.   static const double V_LOC_W;        /* variance of location */
  301.   static const double SHAPE_SCALE2_W; /* Gamma shape param of scale^2*/
  302.   static const double RATE_SCALE2_W;  /* Gamma rate param of scale^2 */
  303.   static const double V_ERROR_W;      /* variance of error */
  304. private:
  305.   double loc_w_;
  306.   double scale2_w_;
  307. };
  308. /*:::::::::::::::::::::: PackMimeHTTP ServerDelay RanVar :::::::::::::::::::*/
  309. class PackMimeHTTPServerDelayRandomVariable : public RandomVariable {
  310. public:
  311.   virtual double value();
  312.   virtual double avg() {return 0;}
  313.   PackMimeHTTPServerDelayRandomVariable();
  314.   PackMimeHTTPServerDelayRandomVariable(double shape, double scale);
  315.   PackMimeHTTPServerDelayRandomVariable(double shape, double scale, RNG* rng);
  316.   static const double SERVER_DELAY_SHAPE;
  317.   static const double SERVER_DELAY_SCALE;
  318.   static const double SERVER_DELAY_DIV;
  319. private:
  320.   double shape_; 
  321.   double scale_; 
  322.   double const_;
  323.   double mean_;
  324. };
  325. #endif