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 #include "ip.h"
00029 #include "tcp.h"
00030 #include "tcp-full.h"
00031 #include "random.h"
00032
00033 #include "ew.h"
00034
00035
00036 HLF::HLF() {
00037 alpha = 0;
00038 high = low = 0;
00039 }
00040
00041 void HLF::reset(double value) {
00042 high = low = value;
00043 }
00044
00045 void HLF::reset() {
00046 reset(0);
00047 }
00048
00049
00050 void HLF::setAlpha(double value) {
00051 if (value > 1 || value < 0)
00052 return;
00053
00054 if (value >= 0.5)
00055 alpha = value;
00056 else
00057 alpha = 1 - value;
00058 }
00059
00060
00061 double HLF::getHigh() {
00062 return(high);
00063 }
00064
00065 double HLF::getLow() {
00066 return(low);
00067 }
00068
00069
00070
00071
00072 void HLF::update(double input) {
00073 high = alpha * high + (1 - alpha) * input;
00074 low = (1 - alpha) * low + alpha * input;
00075
00076 }
00077
00078
00079 TBrateLimitor::TBrateLimitor() {
00080 TBrateLimitor(DEFAULT_TB_RATE_P);
00081 };
00082
00083 TBrateLimitor::TBrateLimitor(double rate) {
00084 double now = Scheduler::instance().clock();
00085 pkt_mode = 1;
00086 bucket_size = DEFAULT_TB_SIZE;
00087 tocken_rate = 0;
00088 tocken_num = bucket_size;
00089 last_time = now;
00090 ini_tocken_rate = rate;
00091
00092 setRate(rate);
00093
00094
00095
00096 resetScore();
00097 };
00098
00099
00100 void TBrateLimitor::setRate(double rate) {
00101 if (rate != tocken_rate) {
00102 last_tocken_rate = tocken_rate;
00103 tocken_rate = rate;
00104 printf("TR %d %.2f %d %d\n", (int)(Scheduler::instance().clock()),
00105 tocken_rate, p_score, n_score);
00106 }
00107 }
00108
00109
00110 void TBrateLimitor::adjustRate() {
00111
00112 adjustScore(-1);
00113
00114 double rate = tocken_rate;
00115 if (p_score >= n_score)
00116 rate = tocken_rate * (1 + 0.2);
00117 else
00118 rate = tocken_rate * (1 - 0.2);
00119
00120 setRate(rate);
00121 }
00122
00123
00124 void TBrateLimitor::resetScore() {
00125 n_score = p_score = 0;
00126 }
00127
00128
00129 void TBrateLimitor::adjustScore(int score) {
00130
00131 if (last_tocken_rate > tocken_rate)
00132 n_score += score;
00133 else
00134 p_score += score;
00135 }
00136
00137 int TBrateLimitor::run(double incoming, double t_rate) {
00138 double now = Scheduler::instance().clock();
00139 double interval = now - last_time;
00140
00141
00142 tocken_num += interval * t_rate;
00143 last_time = now;
00144
00145
00146 if (tocken_num > bucket_size)
00147 tocken_num = bucket_size;
00148
00149
00150
00151
00152 if (tocken_num >= incoming) {
00153 tocken_num -= incoming;
00154
00155 return 0;
00156 }
00157
00158
00159
00160 return 1;
00161 }
00162
00163 int TBrateLimitor::run(double incoming) {
00164 return (run(incoming, tocken_rate));
00165 }
00166
00167
00168
00169 EWdetector::EWdetector() {
00170 ew_src = ew_dst = -1;
00171
00172
00173 cur_rate = avg_rate = 0;
00174
00175
00176 db_timer = dt_timer = 0;
00177
00178
00179 resetAlarm();
00180 resetChange();
00181
00182
00183 hlf.setAlpha(EW_FADING_FACTOR);
00184 }
00185
00186
00187
00188
00189
00190 void EWdetector::setDt(int inv) {
00191 dt_inv = inv;
00192
00193 };
00194 void EWdetector::setDb(int inv) {
00195 db_inv = inv;
00196
00197 };
00198
00199 void EWdetector::setLink(int src, int dst) {
00200 ew_src = src;
00201 ew_dst = dst;
00202
00203 };
00204
00205 void EWdetector::setAlarm() {
00206 alarm = 1;
00207
00208
00209
00210 hlf.reset(avg_rate);
00211 };
00212
00213 void EWdetector::resetAlarm() {
00214 alarm = 0;
00215
00216
00217
00218 hlf.reset(avg_rate);
00219 };
00220
00221
00222 void EWdetector::setChange() {
00223 change = 1;
00224 }
00225
00226 void EWdetector::resetChange() {
00227 change = 0;
00228 }
00229
00230
00231 int EWdetector::testAlarm() {
00232 if (!change)
00233 return(EW_UNCHANGE);
00234 else
00235 return(alarm);
00236 }
00237
00238
00239 void EWdetector::updateAvg() {
00240
00241
00242
00243 hlf.update(cur_rate);
00244
00245
00246
00247
00248
00249
00250
00251 if (!alarm) {
00252
00253 avg_rate = hlf.getLow();
00254 } else {
00255
00256 avg_rate = hlf.getHigh();
00257 }
00258 }
00259
00260
00261 void EWdetector::run(Packet *pkt) {
00262
00263 now = Scheduler::instance().clock();
00264
00265
00266
00267 measure(pkt);
00268
00269
00270 if (now >= dt_timer) {
00271
00272
00273
00274
00275 updateCur();
00276
00277
00278
00279 detect();
00280
00281
00282 updateAvg();
00283
00284
00285 dt_timer = (int)now + dt_inv;
00286
00287
00288 change = 1;
00289 }
00290
00291
00292 if (db_inv && now >= db_timer) {
00293
00294 trace();
00295 db_timer = (int)now + db_inv;
00296 }
00297 }
00298
00299
00300
00301
00302
00303 EWdetectorB::EWdetectorB() : EWdetector() {
00304 drop_p = 0;
00305 arr_count = 0;
00306
00307 adjustor = 1.0;
00308
00309
00310 alist.head = alist.tail = NULL;
00311 alist.count = 0;
00312
00313 swin.head = swin.tail = NULL;
00314 swin.count = swin.ravg = 0;
00315 }
00316
00317
00318 EWdetectorB::~EWdetectorB(){
00319 resetAList();
00320 resetSWin();
00321 }
00322
00323
00324 void EWdetectorB::init(int ew_adj) {
00325
00326 adjustor = ew_adj;
00327 }
00328
00329
00330 void EWdetectorB::measure(Packet *pkt) {
00331
00332
00333 updateAList(pkt);
00334
00335 }
00336
00337
00338 void EWdetectorB::updateCur() {
00339
00340
00341 cur_rate = computeARR();
00342 }
00343
00344
00345 int EWdetectorB::exFlow(Packet *pkt) {
00346
00347
00348 return(0);
00349 }
00350
00351
00352 void EWdetectorB::updateAList(Packet *pkt) {
00353 hdr_cmn* hdr = hdr_cmn::access(pkt);
00354 hdr_ip* iph = hdr_ip::access(pkt);
00355 int dst_id = iph->daddr();
00356 int src_id = iph->saddr();
00357 int f_id = iph->flowid();
00358
00359
00360
00361
00362 AListEntry *p;
00363 p = searchAList(src_id, dst_id, f_id);
00364
00365
00366
00367 if (!p) {
00368 p = newAListEntry(src_id, dst_id, f_id);
00369 }
00370
00371
00372 assert(p && p->f_id == f_id && p->src_id == src_id && p->dst_id == dst_id);
00373
00374
00375 double bytesInTSW, newBytes;
00376 bytesInTSW = p->avg_rate * p->win_length;
00377 newBytes = bytesInTSW + (double) hdr->size();
00378 p->avg_rate = newBytes / (now - p->t_front + p->win_length);
00379 p->t_front = now;
00380
00381
00382 }
00383
00384
00385
00386 int EWdetectorB::getMedianAList(int index, int count) {
00387 int m;
00388
00389 if (!count)
00390 return 0;
00391
00392 sortAList();
00393
00394
00395
00396 m = (int) (count / 2);
00397 if (2 * m == count) {
00398 return((getRateAList(index + m - 1) + getRateAList(index + m)) / 2);
00399 } else {
00400 return(getRateAList(index + m));
00401 }
00402 }
00403
00404
00405 int EWdetectorB::getRateAList(int index) {
00406 struct AListEntry *p;
00407
00408
00409 p = alist.head;
00410 for (int i = 0; i < index; i++) {
00411 if (p)
00412 p = p->next;
00413 }
00414
00415 if (p)
00416 return ((int)p->avg_rate);
00417
00418 printf("Error in AList!\n");
00419 return(0);
00420 }
00421
00422
00423 int EWdetectorB::computeARR() {
00424 int i, agg_rate;
00425
00426
00427
00428
00429 timeoutAList();
00430
00431
00432
00433 if (!alist.count)
00434 return 0;
00435
00436
00437 arr_count = (int) (alist.count * 0.1 + 1);
00438
00439
00440 sortAList();
00441
00442
00443
00444 agg_rate = 0;
00445 for (i = 0; i < arr_count; i++) {
00446 agg_rate += getRateAList(i);
00447 }
00448
00449 if (i)
00450 agg_rate = (int) (agg_rate / i);
00451 else {
00452 printf("No MAX returned from ALIST!!!\n");
00453 }
00454
00455
00456
00457
00458
00459 return(agg_rate);
00460 }
00461
00462
00463 struct AListEntry * EWdetectorB::searchAList(int src_id, int dst_id, int f_id){
00464 AListEntry *p;
00465
00466
00467
00468 timeoutAList();
00469
00470
00471
00472
00473
00474 p = alist.head;
00475 while (p &&
00476 (p->f_id != f_id || p->src_id != src_id || p->dst_id != dst_id)) {
00477 p = p->next;
00478 }
00479
00480 return(p);
00481 }
00482
00483
00484 struct AListEntry * EWdetectorB::newAListEntry(int src_id, int dst_id, int f_id) {
00485 AListEntry *p;
00486
00487 p = new AListEntry;
00488 p->src_id = src_id;
00489 p->dst_id = dst_id;
00490 p->f_id = f_id;
00491 p->last_update = now;
00492 p->avg_rate = 0;
00493
00494
00495 p->t_front = now;
00496 p->win_length = 1;
00497 p->next = NULL;
00498
00499
00500 if (alist.tail)
00501 alist.tail->next = p;
00502 alist.tail = p;
00503
00504 if (!alist.head)
00505 alist.head = p;
00506
00507 alist.count++;
00508
00509 return(p);
00510 }
00511
00512
00513 struct AListEntry * EWdetectorB::getMaxAList() {
00514 struct AListEntry *p, *pp, *max, *pm;
00515
00516
00517
00518 p = pp = alist.head;
00519 max = pm = p;
00520
00521 while (p) {
00522 if (p->avg_rate > max->avg_rate) {
00523 pm = pp;
00524 max = p;
00525 }
00526
00527 pp = p;
00528 p = p->next;
00529 }
00530
00531
00532 if (alist.head == max)
00533 alist.head = max->next;
00534
00535 if (pm != max)
00536 pm->next = max->next;
00537
00538 max->next = NULL;
00539
00540
00541 return(max);
00542 }
00543
00544
00545 void EWdetectorB::sortAList() {
00546 struct AListEntry *max, *head, *tail;
00547
00548 if (!alist.head)
00549 return;
00550
00551
00552 head = tail = NULL;
00553
00554 while (alist.head) {
00555
00556 max = getMaxAList();
00557
00558
00559 if (max) {
00560
00561 if (tail)
00562 tail->next = max;
00563 tail = max;
00564
00565 if (!head)
00566 head = max;
00567 }
00568 }
00569
00570 alist.head = head;
00571 alist.tail = tail;
00572
00573
00574 }
00575
00576
00577 void EWdetectorB::timeoutAList() {
00578 AListEntry *p, *q;
00579 float to;
00580
00581 to = EW_FLOW_TIME_OUT;
00582 if (dt_inv)
00583 to = dt_inv;
00584
00585
00586 p = q = alist.head;
00587 while (p) {
00588
00589 if (p->last_update + to < now){
00590
00591 if (p == alist.head){
00592 if (p == alist.tail) {
00593 alist.head = alist.tail = NULL;
00594 free(p);
00595 p = q = NULL;
00596 } else {
00597 alist.head = p->next;
00598 free(p);
00599 p = q = alist.head;
00600 }
00601 } else {
00602 q->next = p->next;
00603 if (p == alist.tail)
00604 alist.tail = q;
00605 free(p);
00606 p = q->next;
00607 }
00608 alist.count--;
00609 } else {
00610 q = p;
00611 p = q->next;
00612 }
00613 }
00614 }
00615
00616
00617 void EWdetectorB::resetAList() {
00618 struct AListEntry *ap, *aq;
00619
00620 ap = aq = alist.head;
00621 while (ap) {
00622 aq = ap;
00623 ap = ap->next;
00624 free(aq);
00625 }
00626
00627 ap = aq = NULL;
00628 alist.head = alist.tail = NULL;
00629 alist.count = 0;
00630 }
00631
00632
00633
00634
00635 void EWdetectorB::resetSWin() {
00636 struct SWinEntry *p, *q;
00637
00638 p = q = swin.head;
00639 while (p) {
00640 q = p;
00641 p = p->next;
00642 free(q);
00643 }
00644
00645 p = q = NULL;
00646 swin.head = swin.tail = NULL;
00647 swin.count = swin.ravg = 0;
00648 }
00649
00650
00651 void EWdetectorB::updateSWin(int rate) {
00652 struct SWinEntry *p, *new_entry;
00653
00654 new_entry = new SWinEntry;
00655 new_entry->rate = rate;
00656 new_entry->weight = 1;
00657 new_entry->next = NULL;
00658
00659 if (swin.tail)
00660 swin.tail->next = new_entry;
00661 swin.tail = new_entry;
00662
00663 if (!swin.head)
00664 swin.head = new_entry;
00665
00666
00667 if (swin.count < EW_SWIN_SIZE) {
00668 swin.count++;
00669 } else {
00670 p = swin.head;
00671 swin.head = p->next;
00672 free(p);
00673 }
00674 }
00675
00676
00677 void EWdetectorB::ravgSWin() {
00678 struct SWinEntry *p;
00679 float sum = 0;
00680 float t_weight = 0;
00681
00682
00683 p = swin.head;
00684
00685
00686 while (p) {
00687
00688 sum += p->rate * p->weight;
00689 t_weight += p->weight;
00690 p = p->next;
00691 }
00692 p = NULL;
00693
00694
00695 swin.ravg = (int)(sum / t_weight);
00696
00697
00698 }
00699
00700
00701
00702
00703 void EWdetectorB::detect() {
00704
00705
00706
00707
00708 if (alarm) {
00709
00710 if (cur_rate > avg_rate * (1 + EW_DETECT_RANGE)) {
00711
00712 resetAlarm();
00713 }
00714 } else {
00715
00716
00717 if (cur_rate < avg_rate) {
00718 setAlarm();
00719
00720
00721 if (drop_p < EW_MAX_DROP_P)
00722 drop_p = EW_MAX_DROP_P;
00723 } else {
00724 }
00725 }
00726
00727
00728
00729 }
00730
00731
00732 void EWdetectorB::computeDropP() {
00733 double p = 0;
00734
00735 if (alarm) {
00736
00737
00738 p = 1;
00739 if (cur_rate)
00740 p = (avg_rate - cur_rate) * adjustor / cur_rate;
00741
00742
00743 if (p > 1)
00744 p = 1;
00745
00746 if (p < 0)
00747 p = 0;
00748
00749
00750 drop_p = EW_FADING_FACTOR * drop_p + (1 - EW_FADING_FACTOR) * p;
00751
00752 if (drop_p < EW_MIN_DROP_P)
00753 drop_p = EW_MIN_DROP_P;
00754 if (drop_p > EW_MAX_DROP_P)
00755 drop_p = EW_MAX_DROP_P;
00756 } else {
00757
00758 if (drop_p > 0) {
00759 if (drop_p <= EW_MIN_DROP_P)
00760 drop_p = 0;
00761 else {
00762 drop_p = EW_FADING_FACTOR * drop_p;
00763 }
00764 }
00765 }
00766 }
00767
00768
00769 void EWdetectorB::decSInv() {
00770
00771
00772
00773
00774
00775
00776 }
00777
00778
00779 void EWdetectorB::incSInv() {
00780
00781
00782
00783
00784
00785 }
00786
00787
00788 void EWdetectorB::printSWin() {
00789 struct SWinEntry *p;
00790 printf("%f SWIN[%d, %d]", now, swin.ravg, swin.count);
00791 p = swin.head;
00792 int i = 0;
00793 while (p) {
00794 printSWinEntry(p, i++);
00795 p = p->next;
00796 }
00797 p = NULL;
00798 printf("\n");
00799 }
00800
00801
00802 void EWdetectorB::printSWinEntry(struct SWinEntry *p, int i) {
00803 if (p)
00804 printf("[%d: %d %.2f] ", i, p->rate, p->weight);
00805 }
00806
00807
00808 void EWdetectorB::printAListEntry(struct AListEntry *p, int i) {
00809 if (!p)
00810 return;
00811
00812 printf("[%d] %d (%d %d) %.2f %.2f\n", i, p->f_id, p->src_id, p->dst_id,
00813 p->avg_rate, p->last_update);
00814 }
00815
00816
00817
00818 void EWdetectorB::printAList() {
00819 struct AListEntry *p;
00820 printf("%f AList(%d):\n", now, alist.count);
00821
00822 p = alist.head;
00823 int i = 0;
00824 while (p) {
00825 printAListEntry(p, i);
00826 i++;
00827 p = p->next;
00828 }
00829 p = NULL;
00830 printf("\n");
00831 }
00832
00833
00834 void EWdetectorB::trace() {
00835 double db_rate = 0;
00836 double m_rate = 0;
00837
00838 timeoutAList();
00839 m_rate = getMedianAList(0, alist.count);
00840
00841 db_rate = computeARR();
00842
00843 if (!m_rate || !db_rate);
00844
00845
00846 printf("B %d %.2f %.2f %d %d %.2f %.2f\n",
00847 (int)now, cur_rate, avg_rate, arr_count, alarm, db_rate, m_rate);
00848 }
00849
00850
00851 EWdetectorP::EWdetectorP() : EWdetector() {
00852
00853 cur_p.arrival = cur_p.dept = cur_p.drop = 0;
00854 last_p.arrival = last_p.dept = last_p.drop = 0;
00855 last_p_db.arrival = last_p_db.dept = last_p_db.drop = 0;
00856 }
00857
00858 EWdetectorP::~EWdetectorP(){
00859
00860 cur_p.arrival = cur_p.dept = cur_p.drop = 0;
00861 last_p.arrival = last_p.dept = last_p.drop = 0;
00862 }
00863
00864
00865 double EWdetectorP::getRate() {
00866 return(cur_rate);
00867 }
00868
00869
00870 void EWdetectorP::updateStats(int flag) {
00871
00872 if (flag == PKT_ARRIVAL) {
00873 cur_p.arrival++;
00874 return;
00875 }
00876
00877
00878 if (flag == PKT_DEPT) {
00879 cur_p.dept++;
00880 return;
00881 }
00882
00883
00884 if (flag == PKT_DROP) {
00885 cur_p.drop++;
00886 return;
00887 }
00888 }
00889
00890
00891 void EWdetectorP::detect() {
00892 if (cur_rate > avg_rate * (1 + EW_DETECT_RANGE)) {
00893 if (!alarm) {
00894 setAlarm();
00895 }
00896 } else if (cur_rate < avg_rate * (1 - EW_DETECT_RANGE)) {
00897 if (alarm)
00898 resetAlarm();
00899 }
00900 }
00901
00902
00903 void EWdetectorP::updateCur() {
00904
00905 cur_rate = (cur_p.dept - last_p.dept) / dt_inv;
00906
00907
00908 last_p.arrival = cur_p.arrival;
00909 last_p.dept = cur_p.dept;
00910 last_p.drop = cur_p.drop;
00911 }
00912
00913
00914
00915
00916
00917
00918
00919 void EWdetectorP::measure(Packet *pkt) {
00920
00921
00922
00923 }
00924
00925
00926 void EWdetectorP::trace() {
00927 printf("P %d %.2f %.2f %d %d %d %d %d %d %d\n",
00928 (int)now, cur_rate, avg_rate, alarm,
00929 cur_p.arrival - last_p_db.arrival,
00930 cur_p.dept - last_p_db.dept,
00931 cur_p.drop - last_p_db.drop,
00932 cur_p.arrival, cur_p.dept, cur_p.drop);
00933
00934 last_p_db.arrival = cur_p.arrival;
00935 last_p_db.dept = cur_p.dept;
00936 last_p_db.drop = cur_p.drop;
00937 }
00938
00939
00940
00941 EWPolicy::EWPolicy() : Policy() {
00942
00943 ewB = cewB = NULL;
00944 ewP = cewP = NULL;
00945
00946
00947 rlP = rlB = NULL;
00948
00949 max_p = max_b = 0;
00950 alarm = pre_alarm = 0;
00951 change = 0;
00952 }
00953
00954
00955 EWPolicy::~EWPolicy(){
00956 if (ewB)
00957 free(ewB);
00958
00959 if (ewP)
00960 free(ewP);
00961
00962 if (cewB)
00963 free(cewB);
00964
00965 if (cewP)
00966 free(cewP);
00967 }
00968
00969
00970 void EWPolicy::init(int adj, int src, int dst) {
00971 ew_adj = adj;
00972 qsrc = src;
00973 qdst = dst;
00974 }
00975
00976
00977
00978
00979 void EWPolicy::applyMeter(policyTableEntry *policy, Packet *pkt) {
00980 return;
00981 }
00982
00983
00984
00985
00986 int EWPolicy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt) {
00987
00988
00989
00990
00991
00992
00993 hdr_cmn *th = hdr_cmn::access(pkt);
00994 if (th->ptype() == PT_ACK)
00995 return(policer->initialCodePt);
00996
00997
00998
00999
01000 now = Scheduler::instance().clock();
01001
01002
01003 if (ewP)
01004 ewP->updateStats(PKT_ARRIVAL);
01005
01006
01007 if (dropPacket(pkt)) {
01008
01009 if (ewP)
01010 ewP->updateStats(PKT_DROP);
01011
01012
01013 return(policer->downgrade1);
01014 } else {
01015
01016 if (ewP)
01017 ewP->updateStats(PKT_DEPT);
01018
01019
01020 if (ewP)
01021 ewP->run(pkt);
01022
01023 if (ewB)
01024 ewB->run(pkt);
01025
01026
01027 return(policer->initialCodePt);
01028 }
01029 }
01030
01031
01032 void EWPolicy::detect(Packet *pkt) {
01033 int alarm_b, alarm_p;
01034
01035 alarm_b = alarm_p = 0;
01036
01037 if (!ewP || ! cewB)
01038 return;
01039
01040 alarm_b = cewB->testAlarm();
01041 alarm_p = ewP->testAlarm();
01042
01043
01044 if (alarm_p == EW_UNCHANGE || alarm_b == EW_UNCHANGE)
01045 return;
01046
01047
01048
01049 ewP->resetChange();
01050 cewB->resetChange();
01051
01052 change = 1;
01053
01054 pre_alarm = alarm;
01055
01056
01057 if (alarm_b == 0)
01058 alarm = 0;
01059 else if (alarm_p == 0)
01060 alarm = 0;
01061 else
01062 alarm = 1;
01063
01064 printf("ALARM %d %d\n", pre_alarm, alarm);
01065 }
01066
01067
01068 int EWPolicy::dropPacket(Packet *pkt) {
01069
01070
01071
01072
01073
01074 if (cewB && ewP) {
01075
01076
01077
01078 hdr_tcp *tcph = hdr_tcp::access(pkt);
01079
01080 if ((tcph->flags() & TH_SYN) == 0) {
01081
01082 }
01083
01084
01085 detect(pkt);
01086
01087 if (change) {
01088
01089
01090
01091
01092 if (pre_alarm) {
01093 if (alarm) {
01094
01095
01096
01097
01098 if (rlP)
01099 rlP->adjustRate();
01100 } else {
01101
01102 if (rlP)
01103 rlP->adjustScore(1);
01104 }
01105 } else {
01106 if (alarm) {
01107 if (rlP) {
01108
01109 rlP->resetScore();
01110
01111 rlP->setRate(ewP->getRate());
01112 }
01113 } else {
01114
01115 }
01116 }
01117
01118 change = 0;
01119 }
01120 }
01121
01122
01123 if (rlP) {
01124
01125 return(rlP->run(1));
01126 };
01127
01128
01129 return(0);
01130 }
01131
01132
01133 void EWPolicy::detectPr(int dt_inv, int db_inv) {
01134 ewP = new EWdetectorP;
01135 ewP->setLink(qsrc, qdst);
01136 ewP->setDt(dt_inv);
01137 ewP->setDb(db_inv);
01138 }
01139
01140 void EWPolicy::detectPr(int dt_inv) {
01141 detectPr(dt_inv, dt_inv);
01142 }
01143
01144 void EWPolicy::detectPr() {
01145 detectPr(EW_DT_INV, EW_DB_INV);
01146 }
01147
01148
01149 void EWPolicy::detectBr(int dt_inv, int db_inv) {
01150 ewB = new EWdetectorB;
01151 ewB->init(ew_adj);
01152 ewB->setLink(qsrc, qdst);
01153 ewB->setDt(dt_inv);
01154 ewB->setDb(db_inv);
01155 }
01156
01157 void EWPolicy::detectBr(int dt_inv) {
01158 detectBr(dt_inv, dt_inv);
01159 }
01160
01161 void EWPolicy::detectBr() {
01162 detectBr(EW_DT_INV, EW_DB_INV);
01163 }
01164
01165
01166 void EWPolicy::limitPr(double rate) {
01167
01168 rlP = new TBrateLimitor(rate);
01169 };
01170
01171
01172 void EWPolicy::limitBr(double rate) {
01173
01174 rlB = new TBrateLimitor(rate);
01175 };
01176
01177
01178 void EWPolicy::limitPr() {
01179 limitPr(DEFAULT_TB_RATE_P);
01180 };
01181
01182
01183 void EWPolicy::limitBr() {
01184 limitBr(DEFAULT_TB_RATE_B);
01185 };
01186
01187
01188 void EWPolicy::coupleEW(EWPolicy *ewpc) {
01189 coupleEW(ewpc, 0);
01190 }
01191
01192
01193 void EWPolicy::coupleEW(EWPolicy *ewpc, double rate) {
01194
01195 cewB = ewpc->ewB;
01196
01197
01198 if (rate)
01199 limitPr(rate);
01200 else
01201 limitPr();
01202 }
01203