• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/delaybox/delaybox.h

00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 
00003 /* 
00004  * Copyright 2002, The University of North Carolina at Chapel Hill
00005  * 
00006  * Redistribution and use in source and binary forms, with or without 
00007  * modification, are permitted provided that the following conditions are met:
00008  * 
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. The name of the author may not be used to endorse or promote 
00015  * products derived from this software without specific prior written 
00016  * permission.
00017  * 
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 
00019  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
00020  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00021  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 
00022  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00023  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
00024  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
00025  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
00026  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
00027  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00028  * POSSIBILITY OF SUCH DAMAGE.
00029  */
00030 /*
00031  * Reference
00032  *     Stochastic Models for Generating Synthetic HTTP Source Traffic 
00033  *     J. Cao, W.S. Cleveland, Y. Gao, K. Jeffay, F.D. Smith, and M.C. Weigle 
00034  *     IEEE INFOCOM 2004.
00035  *
00036  * Documentation available at http://dirt.cs.unc.edu/delaybox/
00037  * 
00038  * Contacts: Michele Weigle (mcweigle@cs.unc.edu),
00039  *           Kevin Jeffay (jeffay@cs.unc.edu)
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 /*::::::::::::::::: DELAYBOX PAIR ::::::::::::::::::::::::::::::::*/
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 /*::::::::::::::::: DELAYBOX TIMER ::::::::::::::::::::::::::::::::*/
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 /*::::::::::::::::: DELAYBOX QUEUE ::::::::::::::::::::::::::::::::*/
00086 
00087 class DelayBoxQueue {
00088         struct pktinfo {
00089                 pktinfo* next_;  // forward link
00090                 Packet* pkt_;    // packet
00091                 double delta_;   // delta from last pkt
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();        // for debugging
00103 
00104 protected:
00105         pktinfo* head_;         // head of linked list
00106         pktinfo* tail_;         // tail of linked list
00107         double deltasum_;       // sum of deltas in queue
00108 };
00109 
00110 /*::::::::::::::::: DELAYBOX RULE ::::::::::::::::::::::::::::::::*/
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 /*::::::::::::::::: DELAYBOX FLOW ::::::::::::::::::::::::::::::::*/
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 /*::::::::::::::::: DELAYBOX CLASSIFIER ::::::::::::::::::::::::::::::::*/
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_;   // use symmetric delay (same on data/ACK path)
00183 };
00184 
00185 /*::::::::::::::::: DELAYBOX NODE :::::::::::::::::::::::::::::::::::::*/
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 

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