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 #include "classifier.h"
00043 #include "node.h"
00044 #include "ranvar.h"
00045 #include <map>
00046
00047 class DelayBoxClassifier;
00048
00049 void packet_string (char* str, hdr_tcp* tcph, hdr_ip* iph, int size);
00050
00051
00052
00053 class DelayBoxPair {
00054 public:
00055 DelayBoxPair() {};
00056 DelayBoxPair(int s, int d, int f=0) : src_(s), dst_(d), fid_(f) {};
00057 DelayBoxPair(const DelayBoxPair&);
00058 bool operator< (const DelayBoxPair&) const;
00059 bool operator==(const DelayBoxPair&) const;
00060 const DelayBoxPair& operator=(const DelayBoxPair&);
00061 void format (char*) const;
00062 void format_short (char*) const;
00063
00064 protected:
00065 int src_;
00066 int dst_;
00067 int fid_;
00068 };
00069
00070
00071
00072 class DelayBoxTimer : public TimerHandler {
00073 public:
00074 DelayBoxTimer(DelayBoxClassifier *a, int src, int dst, int fid)
00075 : TimerHandler(), a_(a), src_(src), dst_(dst), fid_(fid) {};
00076
00077 protected:
00078 virtual void expire(Event *);
00079 DelayBoxClassifier *a_;
00080 int src_;
00081 int dst_;
00082 int fid_;
00083 };
00084
00085
00086
00087 class DelayBoxQueue {
00088 struct pktinfo {
00089 pktinfo* next_;
00090 Packet* pkt_;
00091 double delta_;
00092 };
00093
00094 public:
00095 DelayBoxQueue() : head_(NULL), tail_(NULL), deltasum_(0) {}
00096 ~DelayBoxQueue();
00097 int empty() { return (head_ == NULL); }
00098 double add(Packet*, double, double);
00099 Packet* dequeue(double*);
00100 void clear();
00101 int oneitem() { return (head_->next_ == NULL); }
00102 void dumplist();
00103
00104 protected:
00105 pktinfo* head_;
00106 pktinfo* tail_;
00107 double deltasum_;
00108 };
00109
00110
00111
00112 class DelayBoxRule {
00113 friend struct DelayBoxClassifier;
00114 public:
00115 DelayBoxRule(RandomVariable* delay, RandomVariable* loss,
00116 RandomVariable* linkspd) : delay_(delay), loss_(loss),
00117 linkspd_(linkspd) {};
00118 DelayBoxRule(RandomVariable* delay, RandomVariable* loss) :
00119 delay_(delay), loss_(loss), linkspd_(NULL) {};
00120 DelayBoxRule(RandomVariable* delay) :
00121 delay_(delay), loss_(NULL), linkspd_(NULL) {};
00122
00123 protected:
00124 RandomVariable* delay_;
00125 RandomVariable* loss_;
00126 RandomVariable* linkspd_;
00127 };
00128
00129
00130
00131 class DelayBoxFlow {
00132 friend struct DelayBoxClassifier;
00133 public:
00134 DelayBoxFlow(double delay, double loss, double linkspd,
00135 DelayBoxQueue* q, DelayBoxTimer* timer) : delay_(delay),
00136 loss_(loss), linkspd_(linkspd), queue_(q), timer_(timer) {};
00137 DelayBoxFlow(const DelayBoxFlow& f);
00138 void format (char*);
00139 void format_delay (char*);
00140
00141 protected:
00142 double delay_;
00143 double loss_;
00144 double linkspd_;
00145 DelayBoxQueue* queue_;
00146 DelayBoxTimer* timer_;
00147 };
00148
00149
00150
00151
00152 class DelayBoxClassifier : public Classifier {
00153 public:
00154 DelayBoxClassifier() : Classifier(), debug_(0), rttfp_(NULL),
00155 symmetric_(1) {};
00156 ~DelayBoxClassifier();
00157 inline double now() {return Scheduler::instance().clock();}
00158 void timeout(int src, int dst, int fid);
00159 void add_rule (const char*const src, const char*const dst,
00160 const char*const dly, const char*const loss,
00161 const char*const linkspd);
00162 void add_rule (const char*const src, const char*const dst,
00163 const char*const dly, const char*const loss);
00164 void add_rule (const char*const src, const char*const dst,
00165 const char*const dly);
00166 void list_rules();
00167 void list_flows();
00168 void output_delay(int src, int dst, int fid, FILE* fp);
00169 inline void set_debug (int d) { debug_ = d; }
00170 inline void set_asymmetric(void) { symmetric_ = 0; }
00171 void setfp (FILE* fp) {rttfp_ = fp;}
00172
00173 protected:
00174 int classify (Packet *p);
00175 void forward_packet (Packet *p);
00176 virtual void recv(Packet *p, Handler *h);
00177
00178 map<DelayBoxPair, DelayBoxRule*> rules_;
00179 map<DelayBoxPair, DelayBoxFlow*> flows_;
00180 int debug_;
00181 FILE* rttfp_;
00182 int symmetric_;
00183 };
00184
00185
00186
00187 class DelayBoxNode : public Node {
00188 public:
00189 DelayBoxNode();
00190 ~DelayBoxNode();
00191 int command(int argc, const char*const* argv);
00192
00193 protected:
00194 DelayBoxClassifier* classifier_;
00195 FILE* rttfp_;
00196 };
00197