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