Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

ew.h

Go to the documentation of this file.
00001 // Copyright (c) 1999 by the University of Southern California
00002 // All rights reserved.
00003 //
00004 // Permission to use, copy, modify, and distribute this software and its
00005 // documentation in source and binary forms for non-commercial purposes
00006 // and without fee is hereby granted, provided that the above copyright
00007 // notice appear in all copies and that both the copyright notice and
00008 // this permission notice appear in supporting documentation. and that
00009 // any documentation, advertising materials, and other materials related
00010 // to such distribution and use acknowledge that the software was
00011 // developed by the University of Southern California, Information
00012 // Sciences Institute.  The name of the University may not be used to
00013 // endorse or promote products derived from this software without
00014 // specific prior written permission.
00015 //
00016 // THE UNIVERSITY OF SOUTHERN CALIFORNIA makes no representations about
00017 // the suitability of this software for any purpose.  THIS SOFTWARE IS
00018 // PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
00019 // INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00020 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 //
00022 // Other copyrights might apply to parts of this software and are so
00023 // noted when applicable.
00024 //
00025 // ew.h (Early warning system)
00026 //   by Xuan Chen (xuanc@isi.edu), USC/ISI
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 // the max and min dropping probability
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 // The default tocken-bucket size and tocken rate (in packet/byte)
00058 #define DEFAULT_TB_SIZE 50
00059 #define DEFAULT_TB_RATE_P 5
00060 #define DEFAULT_TB_RATE_B 1000
00061 
00062 // EW
00063 
00064 // Record the number of packet arrived, departured, and dropped
00065 struct PktRec {
00066   int arrival, dept, drop;
00067 };
00068 
00069 // Record the detection result
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 // List of detection result for aggregates
00082 struct AList {
00083   struct AListEntry *head, *tail;
00084   int count;
00085 };
00086 
00087 // Record the request ratio
00088 struct SWinEntry {
00089   float weight;
00090   int rate;
00091   struct SWinEntry *next;
00092 };
00093 
00094 // Data structure for sliding window
00095 struct SWin {
00096   // counter of entries in the sliding window
00097   int count;
00098   // current running average
00099   int ravg;
00100 
00101   // List of SWin Entries
00102   struct SWinEntry *head;
00103   struct SWinEntry *tail;
00104 };
00105 
00106 // Data structure for High-low filter
00107 // high(t) = alpha * high(t-1) + (1 - alpha) * o(t)
00108 // low(t) = (1 - alpha) * low(t-1) + alpha * o(t)
00109 class HLF {
00110  public:
00111   HLF();
00112 
00113   // configure the HLF
00114   void setAlpha(double);
00115   void reset(double value);
00116   void reset();
00117 
00118   // Get the output of HLF
00119   double getHigh();
00120   double getLow();
00121 
00122   // update high-low filter
00123   void update(double);
00124 
00125  private:
00126   double alpha;
00127   
00128   // the estimated value for the high-pass/low-pass filters
00129   double high, low;
00130 };
00131 
00132 // Definition for a tocken-bucket rate limitor
00133 class TBrateLimitor {
00134  public:
00135   TBrateLimitor();
00136   TBrateLimitor(double);
00137 
00138   // set the rate
00139   void setRate(double);
00140   // adjust the rate
00141   void adjustRate();
00142 
00143   // parameters for a tocken bucket
00144   // the size of the token bucket (in bytes or packets)
00145   double bucket_size;             
00146   // number of tokens in the bucket (in bytes or packets)
00147   double tocken_num;
00148   // the rate to generate tockens
00149   double tocken_rate, ini_tocken_rate, last_tocken_rate;
00150   // last time when updating states
00151   double last_time;
00152 
00153   // in packet or byte mode (packet mode, by default)
00154   int pkt_mode;
00155 
00156   int run(double);
00157   int run(double, double); 
00158 
00159   // states to determine the direction of increasing/decreasing rate
00160   int n_score, p_score;
00161 
00162   // adjust the score for increasing or decreasing scores
00163   void resetScore();
00164   void adjustScore(int);
00165 };
00166 
00167 // Definition for the EW detector
00168 class EWdetector {
00169  public:
00170   EWdetector();
00171   //virtual ~EWdetector() = 0;
00172 
00173   // Enable detecting and debugging rate (eg: pkt or bit rate)
00174   void setDb(int);
00175   void setDt(int);
00176   void setLink(int, int);
00177 
00178   // set and clean alarm
00179   void setAlarm();
00180   void resetAlarm();
00181   int testAlarm();
00182 
00183   void setChange();
00184   void resetChange();
00185   //private:
00186   // The nodes connected by EW
00187   int ew_src, ew_dst;
00188 
00189   // The current time
00190   double now;
00191 
00192   // The timer for detection and debugging
00193   int db_timer, dt_timer;
00194   // Detecting interval
00195   int dt_inv, db_inv;
00196 
00197   // Current rate and long term average
00198   double cur_rate, avg_rate;
00199 
00200   // The alarm flag and proposed dropping probability
00201   int alarm;
00202 
00203   int change;
00204 
00205   // High-low filter
00206   HLF hlf;
00207 
00208   // Detecting engine
00209   void run(Packet *);
00210   // Conduct measurement
00211   virtual void measure(Packet *) = 0;
00212   // Detect changes
00213   virtual void detect() = 0;
00214   // Update current measurement 
00215   virtual void updateCur() = 0;
00216   // Update long term average
00217   void updateAvg();
00218 
00219   // Trace function
00220   virtual void trace() = 0;
00221 
00222 };
00223 
00224 class EWdetectorP : public EWdetector {
00225  public:
00226   EWdetectorP();
00227   virtual ~EWdetectorP();
00228 
00229   // update packet stats
00230   void updateStats(int);
00231   // get the current request rate
00232   double getRate();
00233 
00234  private:
00235   // keep the packet rate stats
00236   PktRec cur_p, last_p, last_p_db;
00237 
00238   // Conduct measurement
00239   void measure(Packet *);
00240   // Detect changes
00241   void detect();
00242   // Update current measurement 
00243   void updateCur();
00244   // Update long term average
00245   void updateAvg();
00246 
00247   // Trace function
00248   void trace();
00249 };
00250 
00251 // EW
00252 class EWdetectorB : public EWdetector {
00253  public:
00254   EWdetectorB();
00255   virtual ~EWdetectorB();
00256 
00257   // Initialize EW
00258   void init(int);
00259 
00260   // Check if the packet belongs to existing flow
00261   int exFlow(Packet *);
00262 
00263  private:
00264   // Adjustor
00265   float adjustor;
00266   float drop_p;
00267   // keep the count of flows for ARR
00268   int arr_count;
00269 
00270   // List to keep the detection results
00271   struct AList alist;
00272   // The sliding window for running average on the aggregated response rate
00273   struct SWin swin;
00274   
00275   // Conduct measurement
00276   void measure(Packet *);
00277   // Update current measurement 
00278   void updateCur();
00279   // Update long term average
00280   void updateAvg();
00281   // Change detection:
00282   // detect the traffic change in aggregated response rate
00283   void detect();
00284   
00285   // Measurement:
00286   // Conduct the measurement and update AList
00287   void updateAList(Packet *);
00288   // Find the max value in AList
00289   struct AListEntry *getMaxAList();
00290   // Sort AList based on the avg_rate
00291   void sortAList();
00292   // Timeout AList entries
00293   void timeoutAList();
00294   // Find the matched AList entry
00295   struct AListEntry * searchAList(int, int, int);
00296   // Add new entry to AList
00297   struct AListEntry * newAListEntry(int, int, int);
00298   // Get the median of AList
00299   int getMedianAList(int, int);
00300   // Get the rate given the index in the list
00301   int getRateAList(int);
00302   // Reset AList
00303   void resetAList();
00304   // Print one entry in AList
00305   void printAListEntry(struct AListEntry *, int);
00306   // output contents in AList
00307   void printAList();
00308 
00309   // Calculate the aggragated response rate for high-bandwidth flows
00310   int computeARR();
00311 
00312   // Determine the dropping probability based on current measurement
00313   void computeDropP();
00314 
00315   // Increase/decrease the sample interval to adjust the detection latency.
00316   void decSInv();
00317   void incSInv();
00318 
00319   // Trace bit rate (resp rate)
00320   void trace();
00321 
00322   // update swin with the latest measurement for one HTab entry.
00323   void updateSWin(int);
00324   // compute the running average on the sliding window
00325   void ravgSWin();
00326   // Reset SWin
00327   void resetSWin();
00328   // output contents in SWin
00329   void printSWin();
00330   // Print one entry in SWin
00331   void printSWinEntry(struct SWinEntry *, int);
00332 };
00333 
00334 // Eearly warning policy: 
00335 //  basically queueing stuffs
00336 class EWPolicy : public Policy {
00337  public:
00338   EWPolicy();
00339   ~EWPolicy();
00340 
00341   void init(int, int, int);
00342   
00343   // Metering and policing methods:
00344   void applyMeter(policyTableEntry *policy, Packet *pkt);
00345   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
00346 
00347   //  make packet drop decisions
00348   int dropPacket(Packet *);
00349   // detect if there is an alarm triggered
00350   void detect(Packet *pkt);
00351   
00352   // Enable detecting and debugging packet rate (eg: req rate)
00353   void detectPr();
00354   void detectPr(int);
00355   void detectPr(int, int);
00356 
00357   // Enable detecting and debugging bit rate (eg: resp rate)
00358   void detectBr();
00359   void detectBr(int);
00360   void detectBr(int, int);
00361  
00362   // Rate limitor: packet rate
00363   void limitPr();
00364   void limitPr(double);
00365   // Rate limitor: bit rate
00366   void limitBr();
00367   void limitBr(double);
00368 
00369   // couple EW detector
00370   void coupleEW(EWPolicy *);
00371   void coupleEW(EWPolicy *, double);
00372 
00373   //protected:
00374   EWdetectorB *ewB, *cewB;
00375   EWdetectorP *ewP, *cewP;
00376 
00377   TBrateLimitor *rlP, *rlB;
00378   
00379  private:
00380   // The current time
00381   double now;
00382   
00383   // indicator for detecting and debugging
00384   int ew_adj, qsrc, qdst;
00385 
00386   // rate limits
00387   int max_p, max_b;
00388 
00389   // ew alarm
00390   int alarm, pre_alarm;
00391   int change;
00392 };
00393 #endif

Generated on Tue Apr 20 12:14:16 2004 for NS2.26SourcesOriginal by doxygen 1.3.3