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
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
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
00089
00090
00091
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
00107
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
00132
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
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
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
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
00243
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