• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/common/mobilenode.h

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: /cvsroot/nsnam/ns-2/common/mobilenode.h,v 1.22 2006/02/21 15:20:18 mahrenho 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 class MobileNode;
00047 
00048 #ifndef __ns_mobilenode_h__
00049 #define __ns_mobilenode_h__
00050 
00051 #define MN_POSITION_UPDATE_INTERVAL     30.0   // seconds
00052 #define MAX_SPEED                       5.0    // meters per second (33.55 mph)
00053 #define MIN_SPEED                       0.0
00054 
00055 
00056 #include "object.h"
00057 #include "trace.h"
00058 #include "lib/bsd-list.h"
00059 #include "phy.h"
00060 #include "topography.h"
00061 #include "arp.h"
00062 #include "node.h"
00063 #include "gridkeeper.h"
00064 #include "energy-model.h"
00065 #include "location.h"
00066 
00067 
00068 
00069 #if COMMENT_ONLY
00070                  -----------------------
00071                 |                       |
00072                 |       Upper Layers    |
00073                 |                       |
00074                  -----------------------
00075                     |               |
00076                     |               |
00077                  -------         -------
00078                 |       |       |       |
00079                 |  LL   |       |  LL   |
00080                 |       |       |       |
00081                  -------         -------
00082                     |               |
00083                     |               |
00084                  -------         -------
00085                 |       |       |       |
00086                 | Queue |       | Queue |
00087                 |       |       |       |
00088                  -------         -------
00089                     |               |
00090                     |               |
00091                  -------         -------
00092                 |       |       |       |
00093                 |  Mac  |       |  Mac  |
00094                 |       |       |       |
00095                  -------         -------
00096                     |               |
00097                     |               |
00098                  -------         -------         -----------------------
00099                 |       |       |       |       |                       |
00100                 | Netif | <---  | Netif | <---  |       Mobile Node     |
00101                 |       |       |       |       |                       |
00102                  -------         -------         -----------------------
00103                     |               |
00104                     |               |
00105                  -----------------------
00106                 |                       |
00107                 |       Channel(s)      |
00108                 |                       |
00109                  -----------------------
00110 #endif
00111 class MobileNode;
00112 
00113 class PositionHandler : public Handler {
00114 public:
00115         PositionHandler(MobileNode* n) : node(n) {}
00116         void handle(Event*);
00117 private:
00118         MobileNode *node;
00119 };
00120 
00121 class MobileNode : public Node
00122 {
00123         friend class PositionHandler;
00124 public:
00125         MobileNode();
00126         virtual int command(int argc, const char*const* argv);
00127 
00128         double  distance(MobileNode*);
00129         double  propdelay(MobileNode*);
00130         void    start(void);
00131         inline void getLoc(double *x, double *y, double *z) {
00132                 update_position();  *x = X_; *y = Y_; *z = Z_;
00133         }
00134         inline void getVelo(double *dx, double *dy, double *dz) {
00135                 *dx = dX_ * speed_; *dy = dY_ * speed_; *dz = 0.0;
00136         }
00137         inline MobileNode* nextnode() { return link_.le_next; }
00138         inline int base_stn() { return base_stn_;}
00139         inline void set_base_stn(int addr) { base_stn_ = addr; }
00140 
00141         void dump(void);
00142 
00143         inline MobileNode*& next() { return next_; }
00144         inline double X() { return X_; }
00145         inline double Y() { return Y_; }
00146         inline double Z() { return Z_; }
00147         inline double speed() { return speed_; }
00148         inline double dX() { return dX_; }
00149         inline double dY() { return dY_; }
00150         inline double dZ() { return dZ_; }
00151         inline double destX() { return destX_; }
00152         inline double destY() { return destY_; }
00153         inline double radius() { return radius_; }
00154         inline double getUpdateTime() { return position_update_time_; }
00155         //inline double last_routingtime() { return last_rt_time_;}
00156 
00157         void update_position();
00158         void log_energy(int);
00159         //void logrttime(double);
00160         virtual void idle_energy_patch(float, float);
00161 
00162         /* For list-keeper */
00163         MobileNode* nextX_;
00164         MobileNode* prevX_;
00165 
00166 protected:
00167         /*
00168          * Last time the position of this node was updated.
00169          */
00170         double position_update_time_;
00171         double position_update_interval_;
00172 
00173         /*
00174          *  The following indicate the (x,y,z) position of the node on
00175          *  the "terrain" of the simulation.
00176          */
00177         double X_;
00178         double Y_;
00179         double Z_;
00180         double speed_;  // meters per second
00181 
00182         /*
00183          *  The following is a unit vector that specifies the
00184          *  direction of the mobile node.  It is used to update
00185          *  position
00186          */
00187         double dX_;
00188         double dY_;
00189         double dZ_;
00190 
00191         /* where are we going? */
00192         double destX_;
00193         double destY_;
00194 
00195         /*
00196          * for gridkeeper use only
00197          */
00198         MobileNode*     next_;
00199         double      radius_;
00200 
00201         // Used to generate position updates
00202         PositionHandler pos_handle_;
00203         Event pos_intr_;
00204 
00205         void    log_movement();
00206         void    random_direction();
00207         void    random_speed();
00208         void    random_destination();
00209         int     set_destination(double x, double y, double speed);
00210 
00211 private:
00212         inline int initialized() {
00213                 return (T_ && log_target_ &&
00214                         X_ >= T_->lowerX() && X_ <= T_->upperX() &&
00215                         Y_ >= T_->lowerY() && Y_ <= T_->upperY());
00216         }
00217         void            random_position();
00218         void            bound_position();
00219         int             random_motion_; // is mobile
00220 
00221         /*
00222          * A global list of mobile nodes
00223          */
00224         LIST_ENTRY(MobileNode) link_;
00225 
00226 
00227         /*
00228          * The topography over which the mobile node moves.
00229          */
00230         Topography *T_;
00231         /*
00232          * Trace Target
00233          */
00234         Trace* log_target_;
00235         /*
00236          * base_stn for mobilenodes communicating with wired nodes
00237          */
00238         int base_stn_;
00239 
00240 
00241         //int last_rt_time_;
00242 };
00243 
00244 #endif // ns_mobilenode_h
00245 
00246 
00247 
00248 
00249 
00250 
00251 
00252 
00253 
00254 
00255 

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