File: errmodel.h

package info (click to toggle)
ns2 2.35%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 78,796 kB
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 816; awk: 525; csh: 355
file content (294 lines) | stat: -rw-r--r-- 9,065 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
/*
 * Copyright (c) 1997 Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the Daedalus Research
 *	Group at the University of California Berkeley.
 * 4. Neither the name of the University nor of the Laboratory may be used
 *    to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Contributed by the Daedalus Research Group, UC Berkeley 
 * (http://daedalus.cs.berkeley.edu)
 *
 * @(#) $Header: /cvsroot/nsnam/ns-2/queue/errmodel.h,v 1.50 2005/04/26 18:56:35 haldar Exp $ (UCB)
 */

#ifndef ns_errmodel_h
#define ns_errmodel_h

#include "connector.h"
#include "timer-handler.h"
#include "ranvar.h"
#include "packet.h"
#include "basetrace.h"

enum ErrorUnit { EU_TIME=0, EU_BYTE, EU_PKT, EU_BIT };
#define EU_NAMES "time", "byte", "pkt", "bit"
#define STR2EU(s) (!strcmp(s,"time") ? EU_TIME : (!strcmp(s,"byte") ? EU_BYTE : (!strcmp(s, "bit") ? EU_BIT : EU_PKT)))

enum StTypeUnit {ST_TIME=0, ST_PKT };
#define ST_NAMES "time", "pkt"
#define STR2ST(s) (!strcmp(s,"time") ? ST_TIME : ST_PKT)

#define EM_GOOD	1
#define EM_BAD	2


/* 
 * Basic object for error models.  This can be used unchanged by error 
 * models that are characterized by a single parameter, the rate of errors 
 * (or equivalently, the mean duration/spacing between errors).  Currently,
 * this includes the uniform and exponentially-distributed models.
 */
class ErrorModel : public Connector {
public:
	ErrorModel();
	virtual void recv(Packet*, Handler*);
	virtual void reset();
	virtual int corrupt(Packet*);
	inline double rate() { return rate_; }
	inline ErrorUnit unit() { return unit_; }
	
protected:
	virtual int command(int argc, const char*const* argv);
	int CorruptPkt(Packet*);
	int CorruptTime(Packet*);
	int CorruptByte(Packet*);
	int CorruptBit(Packet*);
	double PktLength(Packet*);
	double * ComputeBitErrProb(int);

	// event-tracing
	virtual void trace_event(char *eventtype);
	EventTrace *et_;
	
	int enable_;		// true if this error module is turned on
	int markecn_;		// mark ecn instead of dropping on corruption?
	int delay_pkt_;		// delay packet instead of dropping
	int firstTime_;		// to not corrupt first packet in byte model
	ErrorUnit unit_;	// error unit in pkts, bytes, or time
	double rate_;		// uniform error rate in pkt or byte
	double delay_;		// time to delay packet
	double bandwidth_;	// bandwidth of the link
	RandomVariable *ranvar_;// the underlying random variate generator

	int FECstrength_;       // indicate how many corrupted bits are corrected
	int datapktsize_;
	int cntrlpktsize_;
	double *cntrlprb_;
	double *dataprb_;
	Event intr_;		// set callback to queue
	
};

class TwoStateErrorModel;
/* Timer for Errormodels using time to change states */
class TwoStateErrModelTimer : public TimerHandler {
public:
	TwoStateErrModelTimer(TwoStateErrorModel *a, void (TwoStateErrorModel::*call_back)())
		: a_(a), call_back_(call_back) {};
protected:
	virtual void expire (Event *e);
	TwoStateErrorModel *a_;
	void (TwoStateErrorModel::*call_back_)();
};

class TwoStateErrorModel : public ErrorModel {
	friend class ComplexTwoStateErrorModel;
public:
	TwoStateErrorModel();
	virtual int corrupt(Packet*);
	void setunit(ErrorUnit unit) {unit_ = unit;}
protected:
	int command(int argc, const char*const* argv);
	virtual int corruptPkt(Packet* p);
	virtual int corruptTime(Packet* p);
	virtual void checkUnit();
	void transitionState();
	int state_;		// state: 0=error-free, 1=error
	double remainLen_;	// remaining length of the current state
	RandomVariable *ranvar_[2]; // ranvar staying length for each state
	TwoStateErrModelTimer*  twoStateTimer_;
};

class ComplexTwoStateErrorModel : public TwoStateErrorModel {
public:
	ComplexTwoStateErrorModel();
	~ComplexTwoStateErrorModel();
protected:
	int command(int argc, const char*const* argv);
	virtual int corruptPkt(Packet* p);
	virtual int corruptTime(Packet* p);
	TwoStateErrorModel*  em_[2];
};

class MultiStateErrorModel : public ErrorModel {
public:
	MultiStateErrorModel();
	virtual int corrupt(Packet*);
protected:
	int command(int argc, const char*const* argv);
	int sttype_;            // type of state trans: 1: 'pkt' prob, 0: 'time'
	int texpired_;          // timed-state expired?
	double curperiod_;      // the duration of the current state
	double prevTime_;       // the last transition time of current state
	ErrorModel* em_;	// current error model to use
};


/* error model that reads a loss trace (instead of a math/computed model) */
class TraceErrorModel : public ErrorModel {
public:
	TraceErrorModel();
	virtual int match(Packet* p);
	virtual int corrupt(Packet* p);
protected:
	double loss_;
	double good_;
};


/*
 * periodic packet drops (drop every nth packet we see)
 * this can be conveniently combined with a flow-based classifier
 * to achieve drops in particular flows
 */
class PeriodicErrorModel : public ErrorModel {
public:
	PeriodicErrorModel();
	virtual int corrupt(Packet*);
protected:
	int cnt_;
	double period_;
	double offset_;
	double burstlen_;
	double last_time_;
	double first_time_;
	int default_drop_;	// 0 for regular, 1 to drop all
				//   but last pkt in period_
};


/*
 * List error model: specify which packets to drop in tcl
 */
class ListErrorModel : public ErrorModel {
public:
	ListErrorModel() : cnt_(0), droplist_(NULL),
		dropcnt_(0), cur_(0) { }
	~ListErrorModel() { if (droplist_) delete droplist_; }
	virtual int corrupt(Packet*);
	int command(int argc, const char*const* argv);
protected:
	int parse_droplist(int argc, const char *const*);
	static int nextval(const char*&p);
	static int intcomp(const void*, const void*);		// for qsort
	int cnt_;	/* cnt of pkts/bytes we've seen */
	int* droplist_;	/* array of pkt/byte #s to affect */
	int dropcnt_;	/* # entries in droplist_ total */
	int cur_;	/* current index into droplist_ */
};

/* For Selective packet drop */
class SelectErrorModel : public ErrorModel {
public:
	SelectErrorModel();
	virtual int corrupt(Packet*);
protected:
	int command(int argc, const char*const* argv);
	packet_t pkt_type_;
	int drop_cycle_;
	int drop_offset_;
};


/* error model for multicast routing,... now inherits from trace.. later
may make them separate and use pointer/containment.. etc */
class MrouteErrorModel : public TraceErrorModel {
public:
	MrouteErrorModel();
	virtual int match(Packet* p);
	inline int maxtype() { return sizeof(msg_type); }
protected:
	int command(int argc, const char*const* argv);
	char msg_type[15]; /* to which to copy the message code (e.g.
			    *  "prune","join"). It's size is the same
			    * as type_ in prune.h [also returned by maxtype.]
			    */
};

class Classifier;

class ErrorModule : public Connector {
public:
	ErrorModule() : classifier_(0) {}
protected:
	int command(int, const char*const*);
	void recv(Packet*, Handler*);
	Classifier* classifier_;
};

#ifdef HAVE_STL //pgm code uses STL

// PGM error model
class PGMErrorModel : public ErrorModel {
public:
        PGMErrorModel();
        virtual int corrupt(Packet*);

protected:
        int ndrops_;
        int command(int argc, const char*const* argv);
        int pgm_type_;
        int drop_cycle_;
        int drop_offset_;

	int count_;
};

#endif//HAVE_STL

// LMS error model
class LMSErrorModel : public ErrorModel {
public:
        LMSErrorModel();
        virtual int corrupt(Packet*);
 
protected:
	int ndrops_;
	int command(int argc, const char*const* argv);
	packet_t pkt_type_;
	int	drop_cycle_;
	int	drop_offset_;
	int	off_rtp_;
	int	off_lms_;
};




#endif