00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- 00002 * 00003 * Copyright (c) 1997 Regents of the University of California. 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 3. All advertising materials mentioning features or use of this software 00015 * must display the following acknowledgement: 00016 * This product includes software developed by the Computer Systems 00017 * Engineering Group at Lawrence Berkeley Laboratory. 00018 * 4. Neither the name of the University nor of the Laboratory may be used 00019 * to endorse or promote products derived from this software without 00020 * specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00023 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00025 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00028 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00029 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00031 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00032 * SUCH DAMAGE. 00033 * 00034 * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/common/mobilenode.h,v 1.21 2005/01/13 18:33:47 haldar Exp $ 00035 * 00036 */ 00037 00038 /* 00039 * XXX 00040 * Eventually energe model and location stuff in this file will be cleaned 00041 * up and moved to separate file to improve modularity. BUT before that is 00042 * finished, they should stay in this file rather than bothering the base 00043 * node. 00044 */ 00045 00046 #ifndef __ns_mobilenode_h__ 00047 #define __ns_mobilenode_h__ 00048 00049 #define MN_POSITION_UPDATE_INTERVAL 30.0 // seconds 00050 #define MAX_SPEED 5.0 // meters per second (33.55 mph) 00051 #define MIN_SPEED 0.0 00052 00053 00054 #include "object.h" 00055 #include "trace.h" 00056 #include "lib/bsd-list.h" 00057 #include "phy.h" 00058 #include "topography.h" 00059 #include "arp.h" 00060 #include "node.h" 00061 #include "gridkeeper.h" 00062 #include "energy-model.h" 00063 #include "location.h" 00064 00065 class GridKeeper; 00066 00067 #if COMMENT_ONLY 00068 ----------------------- 00069 | | 00070 | Upper Layers | 00071 | | 00072 ----------------------- 00073 | | 00074 | | 00075 ------- ------- 00076 | | | | 00077 | LL | | LL | 00078 | | | | 00079 ------- ------- 00080 | | 00081 | | 00082 ------- ------- 00083 | | | | 00084 | Queue | | Queue | 00085 | | | | 00086 ------- ------- 00087 | | 00088 | | 00089 ------- ------- 00090 | | | | 00091 | Mac | | Mac | 00092 | | | | 00093 ------- ------- 00094 | | 00095 | | 00096 ------- ------- ----------------------- 00097 | | | | | | 00098 | Netif | <--- | Netif | <--- | Mobile Node | 00099 | | | | | | 00100 ------- ------- ----------------------- 00101 | | 00102 | | 00103 ----------------------- 00104 | | 00105 | Channel(s) | 00106 | | 00107 ----------------------- 00108 #endif 00109 00110 class MobileNode; 00111 00112 class PositionHandler : public Handler { 00113 public: 00114 PositionHandler(MobileNode* n) : node(n) {} 00115 void handle(Event*); 00116 private: 00117 MobileNode *node; 00118 }; 00119 00120 class MobileNode : public Node 00121 { 00122 friend class PositionHandler; 00123 public: 00124 MobileNode(); 00125 virtual int command(int argc, const char*const* argv); 00126 00127 double distance(MobileNode*); 00128 double propdelay(MobileNode*); 00129 void start(void); 00130 inline void getLoc(double *x, double *y, double *z) { 00131 update_position(); *x = X_; *y = Y_; *z = Z_; 00132 } 00133 inline void getVelo(double *dx, double *dy, double *dz) { 00134 *dx = dX_ * speed_; *dy = dY_ * speed_; *dz = 0.0; 00135 } 00136 inline MobileNode* nextnode() { return link_.le_next; } 00137 inline int base_stn() { return base_stn_;} 00138 inline void set_base_stn(int addr) { base_stn_ = addr; } 00139 00140 void dump(void); 00141 00142 inline MobileNode*& next() { return next_; } 00143 inline double X() { return X_; } 00144 inline double Y() { return Y_; } 00145 inline double Z() { return Z_; } 00146 inline double speed() { return speed_; } 00147 inline double dX() { return dX_; } 00148 inline double dY() { return dY_; } 00149 inline double dZ() { return dZ_; } 00150 inline double destX() { return destX_; } 00151 inline double destY() { return destY_; } 00152 inline double radius() { return radius_; } 00153 inline double getUpdateTime() { return position_update_time_; } 00154 //inline double last_routingtime() { return last_rt_time_;} 00155 00156 void update_position(); 00157 void log_energy(int); 00158 //void logrttime(double); 00159 virtual void idle_energy_patch(float, float); 00160 00161 /* For list-keeper */ 00162 MobileNode* nextX_; 00163 MobileNode* prevX_; 00164 00165 protected: 00166 /* 00167 * Last time the position of this node was updated. 00168 */ 00169 double position_update_time_; 00170 double position_update_interval_; 00171 00172 /* 00173 * The following indicate the (x,y,z) position of the node on 00174 * the "terrain" of the simulation. 00175 */ 00176 double X_; 00177 double Y_; 00178 double Z_; 00179 double speed_; // meters per second 00180 00181 /* 00182 * The following is a unit vector that specifies the 00183 * direction of the mobile node. It is used to update 00184 * position 00185 */ 00186 double dX_; 00187 double dY_; 00188 double dZ_; 00189 00190 /* where are we going? */ 00191 double destX_; 00192 double destY_; 00193 00194 /* 00195 * for gridkeeper use only 00196 */ 00197 MobileNode* next_; 00198 double radius_; 00199 00200 // Used to generate position updates 00201 PositionHandler pos_handle_; 00202 Event pos_intr_; 00203 00204 void log_movement(); 00205 void random_direction(); 00206 void random_speed(); 00207 void random_destination(); 00208 int set_destination(double x, double y, double speed); 00209 00210 private: 00211 inline int initialized() { 00212 return (T_ && log_target_ && 00213 X_ >= T_->lowerX() && X_ <= T_->upperX() && 00214 Y_ >= T_->lowerY() && Y_ <= T_->upperY()); 00215 } 00216 void random_position(); 00217 void bound_position(); 00218 int random_motion_; // is mobile 00219 00220 /* 00221 * A global list of mobile nodes 00222 */ 00223 LIST_ENTRY(MobileNode) link_; 00224 00225 00226 /* 00227 * The topography over which the mobile node moves. 00228 */ 00229 Topography *T_; 00230 /* 00231 * Trace Target 00232 */ 00233 Trace* log_target_; 00234 /* 00235 * base_stn for mobilenodes communicating with wired nodes 00236 */ 00237 int base_stn_; 00238 00239 00240 //int last_rt_time_; 00241 }; 00242 00243 #endif // ns_mobilenode_h 00244 00245 00246 00247 00248 00249 00250 00251 00252 00253 00254
1.4.6