• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/mobile/god.h

00001 
00002 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00003 /*
00004  * Copyright (c) 1997 Regents of the University of California.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  * 3. All advertising materials mentioning features or use of this software
00016  *    must display the following acknowledgement:
00017  *      This product includes software developed by the Computer Systems
00018  *      Engineering Group at Lawrence Berkeley Laboratory.
00019  * 4. Neither the name of the University nor of the Laboratory may be used
00020  *    to endorse or promote products derived from this software without
00021  *    specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00024  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00027  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00028  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00029  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00032  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00033  * SUCH DAMAGE.
00034  */
00035 /* Ported from CMU/Monarch's code, nov'98 -Padma.*/
00036 /* -*- c++ -*-
00037    god.h
00038 
00039    General Operations Director
00040 
00041    perform operations requiring omnipotence in the simulation
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 // Added by Chalermek  12/1/99
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 // Cut and Paste from setdest.h   -- Chalermek 12/1/99
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   // Added by Chalermek 12/1/99
00145 
00146         int  data_pkt_size;        // in bytes. 
00147         int  num_alive_node;
00148         int  num_connect;
00149         int  num_recv;
00150         int  num_compute;          // number of route-computation times
00151         double prev_time;          // the previous time it computes the route
00152         int  num_data_types;      
00153         int  **source_table;
00154         int  *sink_table;
00155         int  *num_send;            // for each data type
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();     // Look at min_hops to fill in next_hop
00171         void Dump();               // Dump all internal data
00172         bool IsReachable(int i, int j);  // Is node i reachable to node j ?
00173         bool IsNeighbor(int i, int j);   // Is node i a neighbor of node j ?
00174         void ComputeW();           // Initialize the connectivity metrix
00175         void floyd_warshall();     // Calculate the shortest path
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         // Return number of next oifs in ret_num_oif.
00185         // Return array of next oifs as return value of the function.
00186 
00187         int *NextOIFs(int dt, int srcid, int curid, int *ret_num_oif);
00188   
00189         // serve for GAF algorithm
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;   // square array of num_nodesXnum_nodes
00209                          // min_hops[i * num_nodes + j] giving 
00210                          // minhops between i and j
00211         static God*     instance_;
00212 
00213 
00214         // Added by Chalermek    12/1/99
00215 
00216         bool active;
00217         bool allowTostop;
00218         MobileNode **mb_node; // mb_node[i] giving pointer to object 
00219                               // mobile node i
00220         NodeStatus *node_status;
00221         int *next_hop;        // next_hop[i * num_nodes + j] giving
00222                               //   the next hop of i where i wants to send
00223                               //         a packet to j.
00224 
00225         int maxX;          // keeping grid demension info: max X, max Y and 
00226         int maxY;          // grid size
00227         int gridsize_;
00228         int gridX;
00229         int gridY;
00230 
00231 };
00232 
00233 #endif
00234 

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