• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/tools/flowmon.h

00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1990-1997 Regents of the University of California.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *      This product includes software developed by the Computer Systems
00017  *      Engineering Group at Lawrence Berkeley Laboratory.
00018  * 4. Neither the name of the University nor of the Laboratory may be used
00019  *    to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  * @(#) $Header: /cvsroot/nsnam/ns-2/tools/flowmon.h,v 1.2 2004/01/18 19:51:20 haldar Exp $ (LBL)
00035  */
00036 
00037 /* File pulled out of flowmon.cc 
00038  * Hopefully nothing would break as a result
00039  * -ratul
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                 //              bind("off_flags_", &off_flags_);
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_;         /* never overflow */
00102 
00103             if ((double)hdr->size_ < tbucket_ ) {
00104                     //  ((hdr_flags*)p->access(off_flags_))->pri_=1; //Tag the packet as In.
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         /* User defined parameters */
00116         double  target_rate_;           //predefined flow rate in bytes/sec
00117         double  bucket_depth_;          //depth of the token bucket
00118 
00119         double  tbucket_;
00120         /* Dynamic state variables */
00121         double  time_last_sent_;
00122         double  total_in;
00123         double  total_out;
00124         //      int     off_flags_;
00125 };
00126 
00127 /* TaggerTSWFlow will use Time Slide Window to check whehter the data flow 
00128  * stays in the pre-set profile and mark it as In or Out accordingly.
00129  * By Yun Wang, based on Wenjia's algorithm.
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                 //              bind("off_flags_", &off_flags_);
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         /* User-defined parameters. */
00152         double  target_rate_;           //predefined flow rate in bytes/sec
00153         double  win_len_;               //length of the slide window
00154         double  avg_rate_;              //average rate
00155         double  t_front_;
00156         int     count;
00157         int     wait_;
00158 
00159         /* Counters for In/Out packets. */
00160         double  total_in;
00161         double  total_out;
00162         //      int     off_flags_;
00163 };
00164 
00165 /* Tagger performes like the queue monitor with a classifier
00166  * to demux by flow and mark the packets based on the flow profile
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];     // big enough to hold flow list
00183 };
00184 
00185 
00186 /*
00187  * flow monitoring is performed like queue-monitoring with
00188  * a classifier to demux by flow
00189  * ---------------------------------------------------------
00190  * mon_* stuff added to support monitored early drops - ratul
00191  */
00192 
00193 class FlowMon : public EDQueueMonitor {
00194 public:
00195         FlowMon();
00196         void in(Packet*);       // arrivals
00197         void out(Packet*);      // departures
00198         void drop(Packet*);     // all drops (incl 
00199         void edrop(Packet*);    // "early" drops
00200         void mon_edrop(Packet*);        // " monitored early" drops
00201         int command(int argc, const char*const* argv);
00202 
00203         //added by ratul
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_;         // enable per-flow arrival state
00222         int enable_out_;        // enable per-flow depart state
00223         int enable_drop_;       // enable per-flow drop state
00224         int enable_edrop_;      // enable per-flow edrop state
00225         int enable_mon_edrop_;  // enable per-flow mon_edrop state 
00226         
00227         //an excessive high value for large simulations using flow monitor 
00228         char    wrk_[65536];    // big enough to hold flow list
00229 };
00230 
00231 #endif

Generated on Tue Aug 10 2010 16:16:08 for ns-2.33 by  doxygen 1.7.1