• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/mobile/energy-model.h

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: /cvsroot/nsnam/ns-2/mobile/energy-model.h,v 1.13 2005/06/14 19:43:48 haldar 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), er_(0), et_(0),ei_(0), es_(0), 
00092                 initialenergy_(energy), 
00093                 level1_(l1), level2_(l2), node_(n), 
00094                 sleep_mode_(0), total_sleeptime_(0), total_rcvtime_(0), 
00095                 total_sndtime_(0), powersavingflag_(0), 
00096                 last_time_gosleep(0), max_inroute_time_(300), maxttl_(5), 
00097                 adaptivefidelity_(1),  node_on_(true)
00098         {
00099                 neighbor_list.neighbor_cnt_ = 0;
00100                 neighbor_list.head = NULL;
00101         }
00102 
00103         inline double energy() const { return energy_; }
00104 //
00105         inline double et() const { return et_; }
00106         inline double er() const { return er_; }
00107         inline double ei() const { return ei_; }
00108         inline double es() const { return es_; }
00109 //
00110         inline double initialenergy() const { return initialenergy_; }
00111         inline double level1() const { return level1_; }
00112         inline double level2() const { return level2_; }
00113         inline void setenergy(double e) { energy_ = e; }
00114    
00115         virtual void DecrTxEnergy(double txtime, double P_tx);
00116         virtual void DecrRcvEnergy(double rcvtime, double P_rcv);
00117         virtual void DecrIdleEnergy(double idletime, double P_idle);
00118 //
00119         virtual void DecrSleepEnergy(double sleeptime, double P_sleep);
00120         virtual void DecrTransitionEnergy(double transitiontime, double P_transition);
00121 //      
00122         inline virtual double MaxTxtime(double P_tx) {
00123                 return(energy_/P_tx);
00124         }
00125         inline virtual double MaxRcvtime(double P_rcv) {
00126                 return(energy_/P_rcv);
00127         }
00128         inline virtual double MaxIdletime(double P_idle) {
00129                 return(energy_/P_idle);
00130         }
00131 
00132         void add_neighbor(u_int32_t);      // for adaptive fidelity
00133         void scan_neighbor();
00134         inline int getneighbors() { return neighbor_list.neighbor_cnt_; }
00135 
00136         double level1() { return level1_; }
00137         double level2() { return level2_; }
00138         inline int sleep() { return sleep_mode_; }
00139         inline int state() { return state_; }
00140         inline float state_start_time() { return state_start_time_; }
00141         inline float& max_inroute_time() { return max_inroute_time_; }
00142         inline int& adaptivefidelity() { return adaptivefidelity_; }
00143         inline int& powersavingflag() { return powersavingflag_; }
00144         inline bool& node_on() { return node_on_; }
00145         inline float& total_sndtime() { return total_sndtime_; }
00146         inline float& total_rcvtime() { return total_rcvtime_; }
00147         inline float& total_sleeptime() { return total_sleeptime_; }
00148 //
00149         inline float& total_idletime()  {       return total_idletime_;}
00150 //
00151         inline AdaptiveFidelityEntity* afe() { return afe_; }
00152         inline int& maxttl() { return maxttl_; }
00153 
00154         virtual void set_node_sleep(int);
00155         virtual void set_node_state(int);
00156         virtual void add_rcvtime(float t) {total_rcvtime_ += t;}
00157         virtual void add_sndtime(float t) {total_sndtime_ += t;}
00158 //
00159         virtual void add_sleeptime(float t) {total_sleeptime_ += t;};
00160 //
00161         void start_powersaving();
00162 
00163         // Sleeping state
00164         enum SleepState { WAITING = 0, POWERSAVING = 1, INROUTE = 2 };
00165 
00166 protected:
00167         double energy_;
00168 //
00169         double er_; // Total energy consumption in RECV
00170         double et_; // Total energy consumption in transmission
00171         double ei_; // Total energy consumption in IDLE mode
00172         double es_; // Total energy consumption in SLEEP mode
00173 //      
00174         double initialenergy_;
00175         double level1_;
00176         double level2_;
00177 
00178         MobileNode *node_;
00179 
00180         // XXX this structure below can be implemented by ns's LIST
00181         struct neighbor_list_item {
00182                 u_int32_t id;                   // node id
00183                 int       ttl;                  // time-to-live
00184                 neighbor_list_item *next;       // pointer to next item
00185         };
00186 
00187         struct {
00188                 int neighbor_cnt_;   // how many neighbors in this list
00189                 neighbor_list_item *head; 
00190         } neighbor_list;
00191         SoftNeighborHandler *snh_;
00192 
00193         int sleep_mode_;         // = 1: radio is turned off
00194         float total_sleeptime_;  // total time of radio in off mode
00195         float total_rcvtime_;    // total time in receiving data
00196         float total_sndtime_;    // total time in sending data
00197 //
00198         float total_idletime_;  // total time in idle mode
00199 //
00200         int powersavingflag_;    // Is BECA activated ?
00201         float last_time_gosleep; // time when radio is turned off
00202         float max_inroute_time_; // maximum time that a node can remaining
00203                                  // active 
00204         int maxttl_;             // how long a node can keep its neighbor
00205                                  // list. For AFECA only.
00206         int state_;              // used for AFECA state 
00207         float state_start_time_; // starting time of one AFECA state
00208         int adaptivefidelity_;   // Is AFECA activated ?
00209         AdaptiveFidelityEntity *afe_;
00210 
00211         bool node_on_;           // on-off status of this node -- Chalermek
00212 };
00213 
00214 
00215 #endif // ns_energy_model_h

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