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 #ifndef ns_flowmon_h
00043 #define ns_flowmon_h
00044
00045 #include <stdlib.h>
00046 #include "config.h"
00047 #include "queue-monitor.h"
00048 #include "classifier.h"
00049 #include "ip.h"
00050 #include "flags.h"
00051 #include "random.h"
00052
00053 class Flow : public EDQueueMonitor {
00054 public:
00055 Flow() : src_(-1), dst_(-1), fid_(-1), type_(PT_NTYPE) {
00056
00057 bind("src_", (int *) &src_);
00058 bind("dst_", (int *) &dst_);
00059 bind("flowid_", (int *) &fid_);
00060 }
00061 nsaddr_t src() const { return (src_); }
00062 nsaddr_t dst() const { return (dst_); }
00063 int flowid() const { return (fid_); }
00064 packet_t ptype() const { return (type_); }
00065 void setfields(Packet *p) {
00066 hdr_ip* hdr = hdr_ip::access(p);
00067 hdr_cmn* chdr = hdr_cmn::access(p);
00068 src_ = hdr->saddr();
00069 dst_ = hdr->daddr();
00070 fid_ = hdr->flowid();
00071 type_ = chdr->ptype();
00072 }
00073 virtual void tagging(Packet *) {}
00074
00075 protected:
00076 nsaddr_t src_;
00077 nsaddr_t dst_;
00078 int fid_;
00079 packet_t type_;
00080
00081 };
00082
00083 class TaggerTBFlow : public Flow {
00084 public:
00085 TaggerTBFlow() : target_rate_(0.0), time_last_sent_(0.0),
00086 total_in(0.0), total_out(0.0)
00087 {
00088 bind_bw("target_rate_", &target_rate_);
00089 bind("bucket_depth_", &bucket_depth_);
00090 bind("tbucket_", &tbucket_);
00091
00092 }
00093 void tagging(Packet *p) {
00094 hdr_cmn* hdr = hdr_cmn::access(p);
00095 double now = Scheduler::instance().clock();
00096 double time_elapsed;
00097
00098 time_elapsed = now - time_last_sent_;
00099 tbucket_ += time_elapsed * target_rate_ / 8.0;
00100 if (tbucket_ > bucket_depth_)
00101 tbucket_ = bucket_depth_;
00102
00103 if ((double)hdr->size_ < tbucket_ ) {
00104
00105 (hdr_flags::access(p))->pri_=1;
00106 tbucket_ -= hdr->size_;
00107 total_in += 1;
00108 }
00109 else {
00110 total_out += 1;
00111 }
00112 time_last_sent_ = now;
00113 }
00114 protected:
00115
00116 double target_rate_;
00117 double bucket_depth_;
00118
00119 double tbucket_;
00120
00121 double time_last_sent_;
00122 double total_in;
00123 double total_out;
00124
00125 };
00126
00127
00128
00129
00130
00131 class TaggerTSWFlow : public Flow {
00132 public:
00133 TaggerTSWFlow() : target_rate_(0.0), avg_rate_(0.0),
00134 t_front_(0.0), total_in(0.0), total_out(0.0)
00135 {
00136 bind_bw("target_rate_", &target_rate_);
00137 bind("win_len_", &win_len_);
00138 bind_bool("wait_", &wait_);
00139
00140 }
00141 void tagging(Packet *);
00142 void run_rate_estimator(Packet *p, double now){
00143
00144 hdr_cmn* hdr = hdr_cmn::access(p);
00145 double bytes_in_tsw = avg_rate_ * win_len_;
00146 double new_bytes = bytes_in_tsw + hdr->size_;
00147 avg_rate_ = new_bytes / (now - t_front_ + win_len_);
00148 t_front_ = now;
00149 }
00150 protected:
00151
00152 double target_rate_;
00153 double win_len_;
00154 double avg_rate_;
00155 double t_front_;
00156 int count;
00157 int wait_;
00158
00159
00160 double total_in;
00161 double total_out;
00162
00163 };
00164
00165
00166
00167
00168 class Tagger : public EDQueueMonitor {
00169 public:
00170 Tagger() : classifier_(NULL), channel_(NULL) {}
00171 void in(Packet *);
00172 int command(int argc, const char*const* argv);
00173 protected:
00174 void dumpflows();
00175 void dumpflow(Tcl_Channel, Flow*);
00176 void fformat(Flow*);
00177 char* flow_list();
00178
00179 Classifier* classifier_;
00180 Tcl_Channel channel_;
00181
00182 char wrk_[2048];
00183 };
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 class FlowMon : public EDQueueMonitor {
00194 public:
00195 FlowMon();
00196 void in(Packet*);
00197 void out(Packet*);
00198 void drop(Packet*);
00199 void edrop(Packet*);
00200 void mon_edrop(Packet*);
00201 int command(int argc, const char*const* argv);
00202
00203
00204 void setClassifier(Classifier * classifier) {
00205 classifier_ = classifier;
00206 }
00207
00208 Flow * find(Packet* p) {
00209 return (Flow *)classifier_->find(p);
00210 }
00211
00212 protected:
00213 void dumpflows();
00214 void dumpflow(Tcl_Channel, Flow*);
00215 void fformat(Flow*);
00216 char* flow_list();
00217
00218 Classifier* classifier_;
00219 Tcl_Channel channel_;
00220
00221 int enable_in_;
00222 int enable_out_;
00223 int enable_drop_;
00224 int enable_edrop_;
00225 int enable_mon_edrop_;
00226
00227
00228 char wrk_[65536];
00229 };
00230
00231 #endif