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 __god_h
00045 #define __god_h
00046
00047 #include <stdarg.h>
00048 #include "bi-connector.h"
00049 #include "object.h"
00050 #include "packet.h"
00051 #include "trace.h"
00052
00053 #include "node.h"
00054 #include "diffusion/hash_table.h"
00055
00056
00057
00058
00059 #define MIN_HOPS(i,j) min_hops[i*num_nodes+j]
00060 #define NEXT_HOP(i,j) next_hop[i*num_nodes+j]
00061 #define SRC_TAB(i,j) source_table[i*num_nodes+j]
00062 #define SK_TAB(i,j) sink_table[i*num_nodes+j]
00063 #define UNREACHABLE 0x00ffffff
00064 #define RANGE 250.0 // trasmitter range in meters
00065
00066
00067 class NodeStatus {
00068 public:
00069 bool is_source_;
00070 bool is_sink_;
00071 bool is_on_trees_;
00072
00073 NodeStatus() { is_source_ = is_sink_ = is_on_trees_ = false; }
00074 };
00075
00076
00077
00078
00079 class vector {
00080 public:
00081 vector(double x = 0.0, double y = 0.0, double z = 0.0) {
00082 X = x; Y = y; Z = z;
00083 }
00084 double length() {
00085 return sqrt(X*X + Y*Y + Z*Z);
00086 }
00087
00088 inline void operator=(const vector a) {
00089 X = a.X;
00090 Y = a.Y;
00091 Z = a.Z;
00092 }
00093 inline void operator+=(const vector a) {
00094 X += a.X;
00095 Y += a.Y;
00096 Z += a.Z;
00097 }
00098 inline int operator==(const vector a) {
00099 return (X == a.X && Y == a.Y && Z == a.Z);
00100 }
00101 inline int operator!=(const vector a) {
00102 return (X != a.X || Y != a.Y || Z != a.Z);
00103 }
00104 inline vector operator-(const vector a) {
00105 return vector(X-a.X, Y-a.Y, Z-a.Z);
00106 }
00107 friend inline vector operator*(const double a, const vector b) {
00108 return vector(a*b.X, a*b.Y, a*b.Z);
00109 }
00110 friend inline vector operator/(const vector a, const double b) {
00111 return vector(a.X/b, a.Y/b, a.Z/b);
00112 }
00113
00114 double X;
00115 double Y;
00116 double Z;
00117 };
00118
00119
00120
00121
00122 class God : public BiConnector {
00123 public:
00124 God();
00125
00126 int command(int argc, const char* const* argv);
00127
00128 void recv(Packet *p, Handler *h);
00129 void stampPacket(Packet *p);
00130
00131 int initialized() {
00132 return num_nodes && min_hops && uptarget_;
00133 }
00134
00135 int hops(int i, int j);
00136 static God* instance() { assert(instance_); return instance_; }
00137 int nodes() { return num_nodes; }
00138
00139 inline void getGrid(double *x, double *y, double *z) {
00140 *x = maxX; *y = maxY; *z = gridsize_;
00141 }
00142
00143
00144
00145
00146 int data_pkt_size;
00147 int num_alive_node;
00148 int num_connect;
00149 int num_recv;
00150 int num_compute;
00151 double prev_time;
00152 int num_data_types;
00153 int **source_table;
00154 int *sink_table;
00155 int *num_send;
00156 Data_Hash_Table dtab;
00157
00158 void DumpNodeStatus();
00159 void DumpNumSend();
00160 void CountNewData(int *attr);
00161 void IncrRecv();
00162 bool ExistSource();
00163 bool ExistSink();
00164 bool IsPartition();
00165 void StopSimulation();
00166 void CountConnect();
00167 void CountAliveNode();
00168 void ComputeRoute();
00169 int NextHop(int from, int to);
00170 void ComputeNextHop();
00171 void Dump();
00172 bool IsReachable(int i, int j);
00173 bool IsNeighbor(int i, int j);
00174 void ComputeW();
00175 void floyd_warshall();
00176
00177 void AddSink(int dt, int skid);
00178 void AddSource(int dt, int srcid);
00179 void Fill_for_Sink(int dt, int srcid);
00180 void Fill_for_Source(int dt, int skid);
00181 void Rewrite_OIF_Map();
00182 void UpdateNodeStatus();
00183
00184
00185
00186
00187 int *NextOIFs(int dt, int srcid, int curid, int *ret_num_oif);
00188
00189
00190
00191 int load_grid(int,int,int);
00192
00193 int getMyGrid(double x, double y);
00194 int getMyLeftGrid(double x, double y);
00195 int getMyRightGrid(double x, double y);
00196 int getMyTopGrid(double x, double y);
00197 int getMyBottomGrid(double x, double y);
00198
00199 inline int getMyGridSize() {
00200 return gridsize_;
00201 }
00202
00203
00204
00205
00206 private:
00207 int num_nodes;
00208 int* min_hops;
00209
00210
00211 static God* instance_;
00212
00213
00214
00215
00216 bool active;
00217 bool allowTostop;
00218 MobileNode **mb_node;
00219
00220 NodeStatus *node_status;
00221 int *next_hop;
00222
00223
00224
00225 int maxX;
00226 int maxY;
00227 int gridsize_;
00228 int gridX;
00229 int gridY;
00230
00231 };
00232
00233 #endif
00234