• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/queue/errmodel.h

00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1997 Regents of the University of California.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *      This product includes software developed by the Daedalus Research
00017  *      Group at the University of California Berkeley.
00018  * 4. Neither the name of the University nor of the Laboratory may be used
00019  *    to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  * Contributed by the Daedalus Research Group, UC Berkeley 
00035  * (http://daedalus.cs.berkeley.edu)
00036  *
00037  * @(#) $Header: /cvsroot/nsnam/ns-2/queue/errmodel.h,v 1.50 2005/04/26 18:56:35 haldar Exp $ (UCB)
00038  */
00039 
00040 #ifndef ns_errmodel_h
00041 #define ns_errmodel_h
00042 
00043 #include "connector.h"
00044 #include "timer-handler.h"
00045 #include "ranvar.h"
00046 #include "packet.h"
00047 #include "basetrace.h"
00048 
00049 enum ErrorUnit { EU_TIME=0, EU_BYTE, EU_PKT, EU_BIT };
00050 #define EU_NAMES "time", "byte", "pkt", "bit"
00051 #define STR2EU(s) (!strcmp(s,"time") ? EU_TIME : (!strcmp(s,"byte") ? EU_BYTE : (!strcmp(s, "bit") ? EU_BIT : EU_PKT)))
00052 
00053 enum StTypeUnit {ST_TIME=0, ST_PKT };
00054 #define ST_NAMES "time", "pkt"
00055 #define STR2ST(s) (!strcmp(s,"time") ? ST_TIME : ST_PKT)
00056 
00057 #define EM_GOOD 1
00058 #define EM_BAD  2
00059 
00060 
00061 /* 
00062  * Basic object for error models.  This can be used unchanged by error 
00063  * models that are characterized by a single parameter, the rate of errors 
00064  * (or equivalently, the mean duration/spacing between errors).  Currently,
00065  * this includes the uniform and exponentially-distributed models.
00066  */
00067 class ErrorModel : public Connector {
00068 public:
00069         ErrorModel();
00070         virtual void recv(Packet*, Handler*);
00071         virtual void reset();
00072         virtual int corrupt(Packet*);
00073         inline double rate() { return rate_; }
00074         inline ErrorUnit unit() { return unit_; }
00075         
00076 protected:
00077         virtual int command(int argc, const char*const* argv);
00078         int CorruptPkt(Packet*);
00079         int CorruptTime(Packet*);
00080         int CorruptByte(Packet*);
00081         int CorruptBit(Packet*);
00082         double PktLength(Packet*);
00083         double * ComputeBitErrProb(int);
00084 
00085         // event-tracing
00086         virtual void trace_event(char *eventtype);
00087         EventTrace *et_;
00088         
00089         int enable_;            // true if this error module is turned on
00090         int markecn_;           // mark ecn instead of dropping on corruption?
00091         int delay_pkt_;         // delay packet instead of dropping
00092         int firstTime_;         // to not corrupt first packet in byte model
00093         ErrorUnit unit_;        // error unit in pkts, bytes, or time
00094         double rate_;           // uniform error rate in pkt or byte
00095         double delay_;          // time to delay packet
00096         double bandwidth_;      // bandwidth of the link
00097         RandomVariable *ranvar_;// the underlying random variate generator
00098 
00099         int FECstrength_;       // indicate how many corrupted bits are corrected
00100         int datapktsize_;
00101         int cntrlpktsize_;
00102         double *cntrlprb_;
00103         double *dataprb_;
00104         Event intr_;            // set callback to queue
00105         
00106 };
00107 
00108 class TwoStateErrorModel;
00109 /* Timer for Errormodels using time to change states */
00110 class TwoStateErrModelTimer : public TimerHandler {
00111 public:
00112         TwoStateErrModelTimer(TwoStateErrorModel *a, void (TwoStateErrorModel::*call_back)())
00113                 : a_(a), call_back_(call_back) {};
00114 protected:
00115         virtual void expire (Event *e);
00116         TwoStateErrorModel *a_;
00117         void (TwoStateErrorModel::*call_back_)();
00118 };
00119 
00120 class TwoStateErrorModel : public ErrorModel {
00121         friend class ComplexTwoStateErrorModel;
00122 public:
00123         TwoStateErrorModel();
00124         virtual int corrupt(Packet*);
00125         void setunit(ErrorUnit unit) {unit_ = unit;}
00126 protected:
00127         int command(int argc, const char*const* argv);
00128         virtual int corruptPkt(Packet* p);
00129         virtual int corruptTime(Packet* p);
00130         virtual void checkUnit();
00131         void transitionState();
00132         int state_;             // state: 0=error-free, 1=error
00133         double remainLen_;      // remaining length of the current state
00134         RandomVariable *ranvar_[2]; // ranvar staying length for each state
00135         TwoStateErrModelTimer*  twoStateTimer_;
00136 };
00137 
00138 class ComplexTwoStateErrorModel : public TwoStateErrorModel {
00139 public:
00140         ComplexTwoStateErrorModel();
00141         ~ComplexTwoStateErrorModel();
00142 protected:
00143         int command(int argc, const char*const* argv);
00144         virtual int corruptPkt(Packet* p);
00145         virtual int corruptTime(Packet* p);
00146         TwoStateErrorModel*  em_[2];
00147 };
00148 
00149 class MultiStateErrorModel : public ErrorModel {
00150 public:
00151         MultiStateErrorModel();
00152         virtual int corrupt(Packet*);
00153 protected:
00154         int command(int argc, const char*const* argv);
00155         int sttype_;            // type of state trans: 1: 'pkt' prob, 0: 'time'
00156         int texpired_;          // timed-state expired?
00157         double curperiod_;      // the duration of the current state
00158         double prevTime_;       // the last transition time of current state
00159         ErrorModel* em_;        // current error model to use
00160 };
00161 
00162 
00163 /* error model that reads a loss trace (instead of a math/computed model) */
00164 class TraceErrorModel : public ErrorModel {
00165 public:
00166         TraceErrorModel();
00167         virtual int match(Packet* p);
00168         virtual int corrupt(Packet* p);
00169 protected:
00170         double loss_;
00171         double good_;
00172 };
00173 
00174 
00175 /*
00176  * periodic packet drops (drop every nth packet we see)
00177  * this can be conveniently combined with a flow-based classifier
00178  * to achieve drops in particular flows
00179  */
00180 class PeriodicErrorModel : public ErrorModel {
00181 public:
00182         PeriodicErrorModel();
00183         virtual int corrupt(Packet*);
00184 protected:
00185         int cnt_;
00186         double period_;
00187         double offset_;
00188         double burstlen_;
00189         double last_time_;
00190         double first_time_;
00191         int default_drop_;      // 0 for regular, 1 to drop all
00192                                 //   but last pkt in period_
00193 };
00194 
00195 
00196 /*
00197  * List error model: specify which packets to drop in tcl
00198  */
00199 class ListErrorModel : public ErrorModel {
00200 public:
00201         ListErrorModel() : cnt_(0), droplist_(NULL),
00202                 dropcnt_(0), cur_(0) { }
00203         ~ListErrorModel() { if (droplist_) delete droplist_; }
00204         virtual int corrupt(Packet*);
00205         int command(int argc, const char*const* argv);
00206 protected:
00207         int parse_droplist(int argc, const char *const*);
00208         static int nextval(const char*&p);
00209         static int intcomp(const void*, const void*);           // for qsort
00210         int cnt_;       /* cnt of pkts/bytes we've seen */
00211         int* droplist_; /* array of pkt/byte #s to affect */
00212         int dropcnt_;   /* # entries in droplist_ total */
00213         int cur_;       /* current index into droplist_ */
00214 };
00215 
00216 /* For Selective packet drop */
00217 class SelectErrorModel : public ErrorModel {
00218 public:
00219         SelectErrorModel();
00220         virtual int corrupt(Packet*);
00221 protected:
00222         int command(int argc, const char*const* argv);
00223         packet_t pkt_type_;
00224         int drop_cycle_;
00225         int drop_offset_;
00226 };
00227 
00228 
00229 /* error model for multicast routing,... now inherits from trace.. later
00230 may make them separate and use pointer/containment.. etc */
00231 class MrouteErrorModel : public TraceErrorModel {
00232 public:
00233         MrouteErrorModel();
00234         virtual int match(Packet* p);
00235         inline int maxtype() { return sizeof(msg_type); }
00236 protected:
00237         int command(int argc, const char*const* argv);
00238         char msg_type[15]; /* to which to copy the message code (e.g.
00239                             *  "prune","join"). It's size is the same
00240                             * as type_ in prune.h [also returned by maxtype.]
00241                             */
00242 };
00243 
00244 class Classifier;
00245 
00246 class ErrorModule : public Connector {
00247 public:
00248         ErrorModule() : classifier_(0) {}
00249 protected:
00250         int command(int, const char*const*);
00251         void recv(Packet*, Handler*);
00252         Classifier* classifier_;
00253 };
00254 
00255 #ifdef HAVE_STL //pgm code uses STL
00256 
00257 // PGM error model
00258 class PGMErrorModel : public ErrorModel {
00259 public:
00260         PGMErrorModel();
00261         virtual int corrupt(Packet*);
00262 
00263 protected:
00264         int ndrops_;
00265         int command(int argc, const char*const* argv);
00266         int pgm_type_;
00267         int drop_cycle_;
00268         int drop_offset_;
00269 
00270         int count_;
00271 };
00272 
00273 #endif//HAVE_STL
00274 
00275 // LMS error model
00276 class LMSErrorModel : public ErrorModel {
00277 public:
00278         LMSErrorModel();
00279         virtual int corrupt(Packet*);
00280  
00281 protected:
00282         int ndrops_;
00283         int command(int argc, const char*const* argv);
00284         packet_t pkt_type_;
00285         int     drop_cycle_;
00286         int     drop_offset_;
00287         int     off_rtp_;
00288         int     off_lms_;
00289 };
00290 
00291 
00292 
00293 
00294 #endif 

Generated on Tue Aug 10 2010 16:16:08 for ns-2.33 by  doxygen 1.7.1