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 #ifndef EW_H
00029 #define EW_H
00030
00031 #include "packet.h"
00032 #include "dsPolicy.h"
00033
00034 #define EW_MAX_WIN 8
00035 #define EW_SWIN_SIZE 4
00036
00037 #define EW_DETECT_RANGE 0.1
00038 #define EW_MIN_DROP_P 0.1
00039 #define EW_MAX_DROP_P 0.9
00040 #define EW_FLOW_TIME_OUT 10.0
00041
00042 #define EW_SAMPLE_INTERVAL 240
00043 #define EW_DETECT_INTERVAL 60
00044 #define EW_MIN_SAMPLE_INTERVAL 60
00045 #define EW_MIN_DETECT_INTERVAL 15
00046 #define EW_FADING_FACTOR 0.875
00047
00048 #define PKT_ARRIVAL 1001
00049 #define PKT_DEPT 1002
00050 #define PKT_DROP 1003
00051
00052 #define EW_DT_INV 240
00053 #define EW_DB_INV EW_DT_INV
00054
00055 #define EW_UNCHANGE -1
00056
00057
00058 #define DEFAULT_TB_SIZE 50
00059 #define DEFAULT_TB_RATE_P 5
00060 #define DEFAULT_TB_RATE_B 1000
00061
00062
00063
00064
00065 struct PktRec {
00066 int arrival, dept, drop;
00067 };
00068
00069
00070 struct AListEntry {
00071 int src_id;
00072 int dst_id;
00073 int f_id;
00074 double last_update;
00075 double avg_rate;
00076 double t_front;
00077 double win_length;
00078 struct AListEntry *next;
00079 };
00080
00081
00082 struct AList {
00083 struct AListEntry *head, *tail;
00084 int count;
00085 };
00086
00087
00088 struct SWinEntry {
00089 float weight;
00090 int rate;
00091 struct SWinEntry *next;
00092 };
00093
00094
00095 struct SWin {
00096
00097 int count;
00098
00099 int ravg;
00100
00101
00102 struct SWinEntry *head;
00103 struct SWinEntry *tail;
00104 };
00105
00106
00107
00108
00109 class HLF {
00110 public:
00111 HLF();
00112
00113
00114 void setAlpha(double);
00115 void reset(double value);
00116 void reset();
00117
00118
00119 double getHigh();
00120 double getLow();
00121
00122
00123 void update(double);
00124
00125 private:
00126 double alpha;
00127
00128
00129 double high, low;
00130 };
00131
00132
00133 class TBrateLimitor {
00134 public:
00135 TBrateLimitor();
00136 TBrateLimitor(double);
00137
00138
00139 void setRate(double);
00140
00141 void adjustRate();
00142
00143
00144
00145 double bucket_size;
00146
00147 double tocken_num;
00148
00149 double tocken_rate, ini_tocken_rate, last_tocken_rate;
00150
00151 double last_time;
00152
00153
00154 int pkt_mode;
00155
00156 int run(double);
00157 int run(double, double);
00158
00159
00160 int n_score, p_score;
00161
00162
00163 void resetScore();
00164 void adjustScore(int);
00165 };
00166
00167
00168 class EWdetector {
00169 public:
00170 EWdetector();
00171
00172
00173
00174 void setDb(int);
00175 void setDt(int);
00176 void setLink(int, int);
00177
00178
00179 void setAlarm();
00180 void resetAlarm();
00181 int testAlarm();
00182
00183 void setChange();
00184 void resetChange();
00185
00186
00187 int ew_src, ew_dst;
00188
00189
00190 double now;
00191
00192
00193 int db_timer, dt_timer;
00194
00195 int dt_inv, db_inv;
00196
00197
00198 double cur_rate, avg_rate;
00199
00200
00201 int alarm;
00202
00203 int change;
00204
00205
00206 HLF hlf;
00207
00208
00209 void run(Packet *);
00210
00211 virtual void measure(Packet *) = 0;
00212
00213 virtual void detect() = 0;
00214
00215 virtual void updateCur() = 0;
00216
00217 void updateAvg();
00218
00219
00220 virtual void trace() = 0;
00221
00222 };
00223
00224 class EWdetectorP : public EWdetector {
00225 public:
00226 EWdetectorP();
00227 virtual ~EWdetectorP();
00228
00229
00230 void updateStats(int);
00231
00232 double getRate();
00233
00234 private:
00235
00236 PktRec cur_p, last_p, last_p_db;
00237
00238
00239 void measure(Packet *);
00240
00241 void detect();
00242
00243 void updateCur();
00244
00245 void updateAvg();
00246
00247
00248 void trace();
00249 };
00250
00251
00252 class EWdetectorB : public EWdetector {
00253 public:
00254 EWdetectorB();
00255 virtual ~EWdetectorB();
00256
00257
00258 void init(int);
00259
00260
00261 int exFlow(Packet *);
00262
00263 private:
00264
00265 float adjustor;
00266 float drop_p;
00267
00268 int arr_count;
00269
00270
00271 struct AList alist;
00272
00273 struct SWin swin;
00274
00275
00276 void measure(Packet *);
00277
00278 void updateCur();
00279
00280 void updateAvg();
00281
00282
00283 void detect();
00284
00285
00286
00287 void updateAList(Packet *);
00288
00289 struct AListEntry *getMaxAList();
00290
00291 void sortAList();
00292
00293 void timeoutAList();
00294
00295 struct AListEntry * searchAList(int, int, int);
00296
00297 struct AListEntry * newAListEntry(int, int, int);
00298
00299 int getMedianAList(int, int);
00300
00301 int getRateAList(int);
00302
00303 void resetAList();
00304
00305 void printAListEntry(struct AListEntry *, int);
00306
00307 void printAList();
00308
00309
00310 int computeARR();
00311
00312
00313 void computeDropP();
00314
00315
00316 void decSInv();
00317 void incSInv();
00318
00319
00320 void trace();
00321
00322
00323 void updateSWin(int);
00324
00325 void ravgSWin();
00326
00327 void resetSWin();
00328
00329 void printSWin();
00330
00331 void printSWinEntry(struct SWinEntry *, int);
00332 };
00333
00334
00335
00336 class EWPolicy : public Policy {
00337 public:
00338 EWPolicy();
00339 ~EWPolicy();
00340
00341 void init(int, int, int);
00342
00343
00344 void applyMeter(policyTableEntry *policy, Packet *pkt);
00345 int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
00346
00347
00348 int dropPacket(Packet *);
00349
00350 void detect(Packet *pkt);
00351
00352
00353 void detectPr();
00354 void detectPr(int);
00355 void detectPr(int, int);
00356
00357
00358 void detectBr();
00359 void detectBr(int);
00360 void detectBr(int, int);
00361
00362
00363 void limitPr();
00364 void limitPr(double);
00365
00366 void limitBr();
00367 void limitBr(double);
00368
00369
00370 void coupleEW(EWPolicy *);
00371 void coupleEW(EWPolicy *, double);
00372
00373
00374 EWdetectorB *ewB, *cewB;
00375 EWdetectorP *ewP, *cewP;
00376
00377 TBrateLimitor *rlP, *rlB;
00378
00379 private:
00380
00381 double now;
00382
00383
00384 int ew_adj, qsrc, qdst;
00385
00386
00387 int max_p, max_b;
00388
00389
00390 int alarm, pre_alarm;
00391 int change;
00392 };
00393 #endif