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

energy-model.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, 2000 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/mobile/energy-model.h,v 1.11 2000/08/31 20:11:49 haoboy Exp $
00035  */
00036 
00037 // Contributed by Satish Kumar (kkumar@isi.edu)
00038 
00039 #ifndef ns_energy_model_h_
00040 #define ns_energy_model_h_
00041 
00042 #include <cstdlib>
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 #include <assert.h>
00046 
00047 #include "config.h"
00048 #include "trace.h"
00049 #include "rng.h"
00050 
00051 const int CHECKFREQ = 1;
00052 const int MAX_WAITING_TIME = 11;
00053 
00054 class EnergyModel;
00055 
00056 class AdaptiveFidelityEntity : public Handler {
00057 public:  
00058         AdaptiveFidelityEntity(EnergyModel *nid) : nid_(nid) {} 
00059 
00060         virtual void start();
00061         virtual void handle(Event *e);
00062 
00063         virtual void adapt_it();
00064         inline void set_sleeptime(float t) {sleep_time_ = t;}
00065         inline void set_sleepseed(float t) {sleep_seed_ = t;}
00066 
00067 protected:
00068         EnergyModel *nid_;
00069         Event intr;
00070         float  sleep_time_;
00071         float sleep_seed_;
00072         float  idle_time_;
00073 };
00074 
00075 class SoftNeighborHandler : public Handler {
00076 public:
00077         SoftNeighborHandler(EnergyModel *nid) {
00078                 nid_ = nid;
00079         }
00080         virtual void start();
00081         virtual void handle(Event *e); 
00082 protected:
00083         EnergyModel *nid_;
00084         Event  intr;
00085 };
00086 
00087 class MobileNode;
00088 class EnergyModel : public TclObject {
00089 public:
00090         EnergyModel(MobileNode* n, double energy, double l1, double l2) :
00091                 energy_(energy), initialenergy_(energy), 
00092                 level1_(l1), level2_(l2), node_(n), 
00093                 sleep_mode_(0), total_sleeptime_(0), total_rcvtime_(0), 
00094                 total_sndtime_(0), powersavingflag_(0), 
00095                 last_time_gosleep(0), max_inroute_time_(300), maxttl_(5), 
00096                 adaptivefidelity_(0), node_on_(true) 
00097         {
00098                 neighbor_list.neighbor_cnt_ = 0;
00099                 neighbor_list.head = NULL;
00100         }
00101 
00102         inline double energy() const { return energy_; }
00103         inline double initialenergy() const { return initialenergy_; }
00104         inline double level1() const { return level1_; }
00105         inline double level2() const { return level2_; }
00106         inline void setenergy(double e) { energy_ = e; }
00107    
00108         virtual void DecrTxEnergy(double txtime, double P_tx);
00109         virtual void DecrRcvEnergy(double rcvtime, double P_rcv);
00110         virtual void DecrIdleEnergy(double idletime, double P_idle);
00111         inline virtual double MaxTxtime(double P_tx) {
00112                 return(energy_/P_tx);
00113         }
00114         inline virtual double MaxRcvtime(double P_rcv) {
00115                 return(energy_/P_rcv);
00116         }
00117         inline virtual double MaxIdletime(double P_idle) {
00118                 return(energy_/P_idle);
00119         }
00120 
00121         void add_neighbor(u_int32_t);      // for adaptive fidelity
00122         void scan_neighbor();
00123         inline int getneighbors() { return neighbor_list.neighbor_cnt_; }
00124 
00125         double level1() { return level1_; }
00126         double level2() { return level2_; }
00127         inline int sleep() { return sleep_mode_; }
00128         inline int state() { return state_; }
00129         inline float state_start_time() { return state_start_time_; }
00130         inline float& max_inroute_time() { return max_inroute_time_; }
00131         inline int& adaptivefidelity() { return adaptivefidelity_; }
00132         inline int& powersavingflag() { return powersavingflag_; }
00133         inline bool& node_on() { return node_on_; }
00134         inline float& total_sndtime() { return total_sndtime_; }
00135         inline float& total_rcvtime() { return total_rcvtime_; }
00136         inline float& total_sleeptime() { return total_sleeptime_; }
00137         inline AdaptiveFidelityEntity* afe() { return afe_; }
00138         inline int& maxttl() { return maxttl_; }
00139 
00140         virtual void set_node_sleep(int);
00141         virtual void set_node_state(int);
00142         virtual void add_rcvtime(float t) {total_rcvtime_ += t;}
00143         virtual void add_sndtime(float t) {total_sndtime_ += t;}
00144 
00145         void start_powersaving();
00146 
00147         // Sleeping state
00148         enum SleepState { WAITING = 0, POWERSAVING = 1, INROUTE = 2 };
00149 
00150 protected:
00151         double energy_;
00152         double initialenergy_;
00153         double level1_;
00154         double level2_;
00155 
00156         MobileNode *node_;
00157 
00158         // XXX this structure below can be implemented by ns's LIST
00159         struct neighbor_list_item {
00160                 u_int32_t id;                   // node id
00161                 int       ttl;                  // time-to-live
00162                 neighbor_list_item *next;       // pointer to next item
00163         };
00164 
00165         struct {
00166                 int neighbor_cnt_;   // how many neighbors in this list
00167                 neighbor_list_item *head; 
00168         } neighbor_list;
00169         SoftNeighborHandler *snh_;
00170 
00171         int sleep_mode_;         // = 1: radio is turned off
00172         float total_sleeptime_;  // total time of radio in off mode
00173         float total_rcvtime_;    // total time in receiving data
00174         float total_sndtime_;    // total time in sending data
00175         int powersavingflag_;    // Is BECA activated ?
00176         float last_time_gosleep; // time when radio is turned off
00177         float max_inroute_time_; // maximum time that a node can remaining
00178                                  // active 
00179         int maxttl_;             // how long a node can keep its neighbor
00180                                  // list. For AFECA only.
00181         int state_;              // used for AFECA state 
00182         float state_start_time_; // starting time of one AFECA state
00183         int adaptivefidelity_;   // Is AFECA activated ?
00184         AdaptiveFidelityEntity *afe_;
00185 
00186         bool node_on_;           // on-off status of this node -- Chalermek
00187 };
00188 
00189 
00190 #endif // ns_energy_model_h

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