00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
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
00063
00064
00065
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
00086 virtual void trace_event(char *eventtype);
00087 EventTrace *et_;
00088
00089 int enable_;
00090 int markecn_;
00091 int delay_pkt_;
00092 int firstTime_;
00093 ErrorUnit unit_;
00094 double rate_;
00095 double delay_;
00096 double bandwidth_;
00097 RandomVariable *ranvar_;
00098
00099 int FECstrength_;
00100 int datapktsize_;
00101 int cntrlpktsize_;
00102 double *cntrlprb_;
00103 double *dataprb_;
00104 Event intr_;
00105
00106 };
00107
00108 class TwoStateErrorModel;
00109
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_;
00133 double remainLen_;
00134 RandomVariable *ranvar_[2];
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_;
00156 int texpired_;
00157 double curperiod_;
00158 double prevTime_;
00159 ErrorModel* em_;
00160 };
00161
00162
00163
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
00177
00178
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_;
00192
00193 };
00194
00195
00196
00197
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*);
00210 int cnt_;
00211 int* droplist_;
00212 int dropcnt_;
00213 int cur_;
00214 };
00215
00216
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
00230
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];
00239
00240
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
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
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