Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

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  * License is granted to copy, to use, and to make and to use derivative
00006  * works for research and evaluation purposes, provided that Xerox is
00007  * acknowledged in all documentation pertaining to any such copy or derivative
00008  * work. Xerox grants no other licenses expressed or implied. The Xerox trade
00009  * name should not be used in any advertising without its written permission.
00010  *  
00011  * XEROX CORPORATION MAKES NO REPRESENTATIONS CONCERNING EITHER THE
00012  * MERCHANTABILITY OF THIS SOFTWARE OR THE SUITABILITY OF THIS SOFTWARE
00013  * FOR ANY PARTICULAR PURPOSE.  The software is provided "as is" without
00014  * express or implied warranty of any kind.
00015  *  
00016  * These notices must be retained in any copies of any part of this software.
00017  *
00018  * This file contributed by Suchitra Raman <sraman@parc.xerox.com>, June 1997.
00019  */
00020 
00021 #ifndef srm_topo_h
00022 #define srm_topo_h
00023 #include "scheduler.h"
00024 #include "random.h"
00025 
00026 #define tprintf(x) { \
00027         Scheduler &_s = Scheduler::instance(); \
00028         double _now = _s.clock(); \
00029         printf("%f : ", _now); \
00030         printf x;\
00031         fflush(stdout);\
00032 }              
00033 #define SRM_DATA 0
00034 #define SRM_RREQ 1
00035 #define SRM_PENDING_RREQ 2
00036 
00037 
00038 #define SRM_SUPPRESS 0
00039 #define SRM_NO_SUPPRESS 1
00040 #define SRM_NOIF -1
00041 
00042 
00043 /* 
00044  * Events -- passed on from node to node 
00045  */
00046 class SRM_Event : public Event {
00047  public:
00048         SRM_Event(int s=0, int t=0, int i=0) : seqno_(s), iif_(i), type_(t) {}
00049         SRM_Event(SRM_Event *e);
00050         int seqno() { return seqno_; }
00051         int iif() { return iif_; }
00052 
00053         int type() { return type_; }    
00054         void type(int t) { type_ = t; }
00055         void iif(int i) { iif_ = i; }
00056 
00057  protected:
00058         int seqno_;
00059         int iif_;
00060         int type_;
00061 };
00062 
00063 
00064 /* 
00065  * SRM_Request - Stored version of request to cancel when a similar
00066  * request is heard. Right now, a request only has an ID.
00067  * A real implementation would have a sequence range, if ADUs
00068  * were stacked.
00069  */
00070 
00071 class SRM_Request {
00072  public:
00073         SRM_Request(SRM_Event *e) : event_(e), next_(0) {};
00074         ~SRM_Request();
00075         void cancel_timer();
00076 
00077         SRM_Event *event_;
00078         SRM_Request *next_;
00079 };
00080 
00081 
00082 /* 
00083  * Light-weight node abstraction only to store SRM 
00084  * protocol state information.
00085  */
00086 class SrmNode : public Handler {
00087  public:
00088         SrmNode() : id_(0), expected_(0), pending_(0) {}
00089         void id(int i) { id_ = i; }
00090         void handle(Event *);
00091         void send(SRM_Event *);
00092 
00093         void append(SRM_Event *);
00094         void remove(int , int);
00095 
00096 
00097  protected:
00098         void sched_nack(int);
00099         void dump_packet(SRM_Event *e);
00100 
00101         int id_;
00102         int expected_;
00103         SRM_Request *pending_;
00104 };
00105 
00106 
00107 /*
00108  * Interface -- Contains the node id of a node and 
00109  * a pointer to the next Interface 
00110  */
00111 class Interface {
00112  public: 
00113         Interface(int in) : in_(in), next_(0) { }
00114 
00115         int in_;
00116         Interface *next_;
00117 };
00118 
00119 class Interface_List {
00120  public: 
00121         Interface_List() : head_(0) { }
00122         ~Interface_List();
00123         void append(int in);
00124 
00125         Interface* head_;
00126 };
00127 
00128 
00129 /* 
00130  * Topology -- Line, Tree, Star derived from this base class.
00131  */
00132 class Topology *topology; 
00133 
00134 class Topology : public TclObject {
00135  public:
00136         Topology(int nn, int src);
00137         ~Topology();
00138         virtual void flood(int, int) = 0;
00139         virtual Interface_List *oif(int node, int iif) = 0;
00140 
00141         int command(int argc, const char*const* argv);
00142         inline int idx() { return idx_; }
00143         SrmNode *node(int nn);
00144         virtual double backoff(int dst) = 0;
00145         inline double delay() { return delay_;}
00146         inline double D() { return D_;}
00147         virtual double delay(int src, int dst) = 0;
00148         int rtt_estimated() { return rtt_est_; }
00149 
00150  protected:
00151         SrmNode *node_; 
00152         int idx_;
00153         int src_;
00154 
00155         double delay_;
00156         double D_;
00157         double frac_;
00158         double det_;
00159         double rand_;
00160         int rtt_est_;
00161 };
00162 
00163 /* 
00164  * Line -- Chain with 'nn' nodes 
00165  */
00166 class Line : public Topology {
00167  public: 
00168         Line(int n, int src) : Topology(n, src) { 
00169                 topology = this; 
00170                 bind("c_", &c_);
00171                 bind("alpha_", &alpha_);
00172                 bind("beta_", &beta_);          
00173                 bind("c2func_", &c2func_);              
00174         }
00175         void flood(int, int);
00176         Interface_List *oif(int node, int iif);
00177         double backoff(int dst);
00178         double delay(int src, int dst); 
00179  protected:
00180         int src_;
00181         int c_;
00182         double alpha_;
00183         double beta_;
00184         int c2func_;
00185 };
00186 
00187 #define LOG  0
00188 #define SQRT 1
00189 #define LINEAR 2
00190 #define CONSTANT 3
00191 
00192 /* 
00193  * BTree -- Binary Tree with 'nn' nodes 
00194  */
00195 class BTree : public Topology {
00196  public: 
00197         BTree(int n, int src) : Topology(n, src) { 
00198                 topology = this; 
00199                 bind("c_", &c_);
00200                 bind("alpha_", &alpha_);
00201                 bind("beta_", &beta_);
00202                 bind("c2func_", &c2func_);
00203         }
00204         void flood(int, int);
00205         Interface_List *oif(int node, int iif);
00206         double backoff(int dst);
00207         double delay(int src, int dst); 
00208 
00209  protected:
00210         int src_;
00211         int c_;
00212         double alpha_;
00213         double beta_;
00214         int c2func_;
00215 };
00216 
00217 
00218 /* 
00219  * Star -- Complete graph with (nn-1) receivers and 1 sender 
00220  * at a distance 'Delay_' from each receiver. 
00221  */
00222 class Star : public Topology {
00223  public:
00224         Star(int n, int src) : Topology(n, src) { 
00225                 topology = this; 
00226 
00227                 bind("c_", &c_);
00228                 bind("alpha_", &alpha_);
00229                 bind("beta_", &beta_);
00230         }
00231 
00232         void flood(int, int);
00233         Interface_List *oif(int node, int iif);
00234         double backoff(int dst);
00235         inline int c() { return c_; }
00236         double delay(int src, int dst); 
00237 
00238  protected:
00239         int src_;
00240         int c_;
00241         double alpha_;
00242         double beta_;
00243 };
00244 #endif 
00245 
00246 
00247 
00248 
00249 

Generated on Tue Apr 20 12:14:33 2004 for NS2.26SourcesOriginal by doxygen 1.3.3