srm-topo.h

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) Xerox Corporation 1997. All rights reserved.
00004  *  
00005  * This program is free software; you can redistribute it and/or modify it
00006  * under the terms of the GNU General Public License as published by the
00007  * Free Software Foundation; either version 2 of the License, or (at your
00008  * option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along
00016  * with this program; if not, write to the Free Software Foundation, Inc.,
00017  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  *
00019  * Linking this file statically or dynamically with other modules is making
00020  * a combined work based on this file.  Thus, the terms and conditions of
00021  * the GNU General Public License cover the whole combination.
00022  *
00023  * In addition, as a special exception, the copyright holders of this file
00024  * give you permission to combine this file with free software programs or
00025  * libraries that are released under the GNU LGPL and with code included in
00026  * the standard release of ns-2 under the Apache 2.0 license or under
00027  * otherwise-compatible licenses with advertising requirements (or modified
00028  * versions of such code, with unchanged license).  You may copy and
00029  * distribute such a system following the terms of the GNU GPL for this
00030  * file and the licenses of the other code concerned, provided that you
00031  * include the source code of that other code when and as the GNU GPL
00032  * requires distribution of source code.
00033  *
00034  * Note that people who make modified versions of this file are not
00035  * obligated to grant this special exception for their modified versions;
00036  * it is their choice whether to do so.  The GNU General Public License
00037  * gives permission to release a modified version without this exception;
00038  * this exception also makes it possible to release a modified version
00039  * which carries forward this exception.
00040  *
00041  * This file contributed by Suchitra Raman <sraman@parc.xerox.com>, June 1997.
00042  */
00043 
00044 #ifndef srm_topo_h
00045 #define srm_topo_h
00046 #include "scheduler.h"
00047 #include "random.h"
00048 
00049 #define tprintf(x) { \
00050     Scheduler &_s = Scheduler::instance(); \
00051     double _now = _s.clock(); \
00052     printf("%f : ", _now); \
00053     printf x;\
00054     fflush(stdout);\
00055 }              
00056 #define SRM_DATA 0
00057 #define SRM_RREQ 1
00058 #define SRM_PENDING_RREQ 2
00059 
00060 
00061 #define SRM_SUPPRESS 0
00062 #define SRM_NO_SUPPRESS 1
00063 #define SRM_NOIF -1
00064 
00065 
00066 /* 
00067  * Events -- passed on from node to node 
00068  */
00069 class SRM_Event : public Event {
00070  public:
00071     SRM_Event(int s=0, int t=0, int i=0) : seqno_(s), iif_(i), type_(t) {}
00072     SRM_Event(SRM_Event *e);
00073     int seqno() { return seqno_; }
00074     int iif() { return iif_; }
00075 
00076     int type() { return type_; }    
00077     void type(int t) { type_ = t; }
00078     void iif(int i) { iif_ = i; }
00079 
00080  protected:
00081     int seqno_;
00082     int iif_;
00083     int type_;
00084 };
00085 
00086 
00087 /* 
00088  * SRM_Request - Stored version of request to cancel when a similar
00089  * request is heard. Right now, a request only has an ID.
00090  * A real implementation would have a sequence range, if ADUs
00091  * were stacked.
00092  */
00093 
00094 class SRM_Request {
00095  public:
00096     SRM_Request(SRM_Event *e) : event_(e), next_(0) {};
00097     ~SRM_Request();
00098     void cancel_timer();
00099 
00100     SRM_Event *event_;
00101     SRM_Request *next_;
00102 };
00103 
00104 
00105 /* 
00106  * Light-weight node abstraction only to store SRM 
00107  * protocol state information.
00108  */
00109 class SrmNode : public Handler {
00110  public:
00111     SrmNode() : id_(0), expected_(0), pending_(0) {}
00112     void id(int i) { id_ = i; }
00113     void handle(Event *);
00114     void send(SRM_Event *);
00115 
00116     void append(SRM_Event *);
00117     void remove(int , int);
00118 
00119 
00120  protected:
00121     void sched_nack(int);
00122     void dump_packet(SRM_Event *e);
00123 
00124     int id_;
00125     int expected_;
00126     SRM_Request *pending_;
00127 };
00128 
00129 
00130 /*
00131  * Interface -- Contains the node id of a node and 
00132  * a pointer to the next Interface 
00133  */
00134 class Interface {
00135  public: 
00136     Interface(int in) : in_(in), next_(0) { }
00137 
00138     int in_;
00139     Interface *next_;
00140 };
00141 
00142 class Interface_List {
00143  public: 
00144     Interface_List() : head_(0) { }
00145     ~Interface_List();
00146     void append(int in);
00147 
00148     Interface* head_;
00149 };
00150 
00151 
00152 /* 
00153  * Topology -- Line, Tree, Star derived from this base class.
00154  */
00155 class Topology *topology; 
00156 
00157 class Topology : public TclObject {
00158  public:
00159     Topology(int nn, int src);
00160     ~Topology();
00161     virtual void flood(int, int) = 0;
00162     virtual Interface_List *oif(int node, int iif) = 0;
00163 
00164     int command(int argc, const char*const* argv);
00165     inline int idx() { return idx_; }
00166     SrmNode *node(int nn);
00167     virtual double backoff(int dst) = 0;
00168     inline double delay() { return delay_;}
00169     inline double D() { return D_;}
00170     virtual double delay(int src, int dst) = 0;
00171     int rtt_estimated() { return rtt_est_; }
00172 
00173  protected:
00174     SrmNode *node_; 
00175     int idx_;
00176     int src_;
00177 
00178     double delay_;
00179     double D_;
00180     double frac_;
00181     double det_;
00182     double rand_;
00183     int rtt_est_;
00184 };
00185 
00186 /* 
00187  * Line -- Chain with 'nn' nodes 
00188  */
00189 class Line : public Topology {
00190  public: 
00191     Line(int n, int src) : Topology(n, src) { 
00192         topology = this; 
00193         bind("c_", &c_);
00194         bind("alpha_", &alpha_);
00195         bind("beta_", &beta_);      
00196         bind("c2func_", &c2func_);      
00197     }
00198     void flood(int, int);
00199     Interface_List *oif(int node, int iif);
00200     double backoff(int dst);
00201     double delay(int src, int dst); 
00202  protected:
00203     int src_;
00204     int c_;
00205     double alpha_;
00206     double beta_;
00207     int c2func_;
00208 };
00209 
00210 #define LOG  0
00211 #define SQRT 1
00212 #define LINEAR 2
00213 #define CONSTANT 3
00214 
00215 /* 
00216  * BTree -- Binary Tree with 'nn' nodes 
00217  */
00218 class BTree : public Topology {
00219  public: 
00220     BTree(int n, int src) : Topology(n, src) { 
00221         topology = this; 
00222         bind("c_", &c_);
00223         bind("alpha_", &alpha_);
00224         bind("beta_", &beta_);
00225         bind("c2func_", &c2func_);
00226     }
00227     void flood(int, int);
00228     Interface_List *oif(int node, int iif);
00229     double backoff(int dst);
00230     double delay(int src, int dst); 
00231 
00232  protected:
00233     int src_;
00234     int c_;
00235     double alpha_;
00236     double beta_;
00237     int c2func_;
00238 };
00239 
00240 
00241 /* 
00242  * Star -- Complete graph with (nn-1) receivers and 1 sender 
00243  * at a distance 'Delay_' from each receiver. 
00244  */
00245 class Star : public Topology {
00246  public:
00247     Star(int n, int src) : Topology(n, src) { 
00248         topology = this; 
00249 
00250         bind("c_", &c_);
00251         bind("alpha_", &alpha_);
00252         bind("beta_", &beta_);
00253     }
00254 
00255     void flood(int, int);
00256     Interface_List *oif(int node, int iif);
00257     double backoff(int dst);
00258     inline int c() { return c_; }
00259     double delay(int src, int dst); 
00260 
00261  protected:
00262     int src_;
00263     int c_;
00264     double alpha_;
00265     double beta_;
00266 };
00267 #endif 
00268 
00269 
00270 
00271 
00272 

Generated on Tue Mar 6 16:47:51 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6