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

mobilenode.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) 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.17 2001/02/07 10:25:35 yaxu 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 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 last_routingtime() { return last_rt_time_;}
00154 
00155         void update_position();
00156         void log_energy(int);
00157         //void logrttime(double);
00158         virtual void idle_energy_patch(float, float);
00159 
00160 protected:
00161         /*
00162          * Last time the position of this node was updated.
00163          */
00164         double position_update_time_;
00165         double position_update_interval_;
00166 
00167         /*
00168          *  The following indicate the (x,y,z) position of the node on
00169          *  the "terrain" of the simulation.
00170          */
00171         double X_;
00172         double Y_;
00173         double Z_;
00174         double speed_;  // meters per second
00175 
00176         /*
00177          *  The following is a unit vector that specifies the
00178          *  direction of the mobile node.  It is used to update
00179          *  position
00180          */
00181         double dX_;
00182         double dY_;
00183         double dZ_;
00184 
00185         /* where are we going? */
00186         double destX_;
00187         double destY_;
00188 
00189         /*
00190          * for gridkeeper use only
00191          */
00192         MobileNode*     next_;
00193         double          radius_;
00194 
00195         // Used to generate position updates
00196         PositionHandler pos_handle_;
00197         Event pos_intr_;
00198 
00199         void    log_movement();
00200         void    random_direction();
00201         void    random_speed();
00202         void    random_destination();
00203         int     set_destination(double x, double y, double speed);
00204           
00205 private:
00206         inline int initialized() {
00207                 return (T_ && log_target_ &&
00208                         X_ >= T_->lowerX() && X_ <= T_->upperX() &&
00209                         Y_ >= T_->lowerY() && Y_ <= T_->upperY());
00210         }
00211         void            random_position();
00212         void            bound_position();
00213         int             random_motion_; // is mobile
00214 
00215         /*
00216          * A global list of mobile nodes
00217          */
00218         LIST_ENTRY(MobileNode) link_;
00219         /*
00220          * The topography over which the mobile node moves.
00221          */
00222         Topography *T_;
00223         /*
00224          * Trace Target
00225          */
00226         Trace* log_target_;
00227         /* 
00228          * base_stn for mobilenodes communicating with wired nodes
00229          */
00230         int base_stn_;
00231 
00232 
00233         //int last_rt_time_;
00234 };
00235 
00236 #endif // ns_mobilenode_h

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