wireless-phy.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/mac/wireless-phy.h,v 1.14 2005/06/13 17:50:41 haldar Exp $
00035  *
00036  * Ported from CMU/Monarch's code, nov'98 -Padma Haldar.
00037  *
00038  * wireless-phy.h
00039  * -- a SharedMedia network interface
00040  */
00041 
00042 #ifndef ns_WirelessPhy_h
00043 #define ns_WirelessPhy_h
00044 
00045 #include "propagation.h"
00046 #include "modulation.h"
00047 #include "omni-antenna.h"
00048 #include "phy.h"
00049 #include "mobilenode.h"
00050 #include "timer-handler.h"
00051 
00052 class Phy;
00053 class Propagation;
00054 class WirelessPhy;
00055 
00056 class Sleep_Timer : public TimerHandler {
00057  public:
00058     Sleep_Timer(WirelessPhy *a) : TimerHandler() { a_ = a; }
00059  protected:
00060     virtual void expire(Event *e);
00061     WirelessPhy *a_;
00062 };
00063 
00064 //
00065 class WirelessPhy : public Phy {
00066 public:
00067     WirelessPhy();
00068     
00069     void sendDown(Packet *p);
00070     int sendUp(Packet *p);
00071     
00072     inline double getL() const {return L_;}
00073     inline double getLambda() const {return lambda_;}
00074     inline Node* node(void) const { return node_; }
00075     inline double getPtconsume() { return Pt_consume_; }
00076 
00077     double getDist(double Pr, double Pt, double Gt, double Gr, double hr,
00078                double ht, double L, double lambda);
00079   
00080     virtual int command(int argc, const char*const* argv);
00081     virtual void dump(void) const;
00082     
00083     //void setnode (MobileNode *node) { node_ = node; }
00084     void node_on();
00085     void node_off();    
00086 
00087         /* -NEW- */
00088         inline double getAntennaZ() { return ant_->getZ(); }
00089         inline double getPt() { return Pt_; }
00090         inline double getRXThresh() { return RXThresh_; }
00091         inline double getCSThresh() { return CSThresh_; }
00092         inline double getFreq() { return freq_; }
00093         /* End -NEW- */
00094 
00095     void node_sleep();
00096     void node_wakeup();
00097     inline bool& Is_node_on() { return node_on_; }
00098     inline bool Is_sleeping() { if (status_==SLEEP) return(1); else return(0); }
00099 
00100 protected:
00101     double Pt_;     // transmitted signal power (W)
00102     double Pt_consume_; // power consumption for transmission (W)
00103     double Pr_consume_; // power consumption for reception (W)
00104     double P_idle_;         // idle power consumption (W)
00105     double P_sleep_;    // sleep power consumption (W)
00106     double P_transition_;   // power consumed when transiting from SLEEP mode to IDLE mode and vice versa.
00107     double T_transition_;   // time period to transit from SLEEP mode to IDLE mode and vice versa.
00108 //
00109 
00110     double last_send_time_; // the last time the node sends somthing.
00111     double channel_idle_time_;  // channel idle time.
00112     double update_energy_time_; // the last time we update energy.
00113 
00114     double freq_;           // frequency
00115     double lambda_;     // wavelength (m)
00116     double L_;      // system loss factor
00117   
00118     double RXThresh_;   // receive power threshold (W)
00119     double CSThresh_;   // carrier sense threshold (W)
00120     double CPThresh_;   // capture threshold (db)
00121   
00122     Antenna *ant_;
00123     Propagation *propagation_;  // Propagation Model
00124     Modulation *modulation_;    // Modulation Schem
00125 
00126     // Why phy has a node_ and this guy has it all over again??
00127 //      MobileNode* node_;          // Mobile Node to which interface is attached .
00128 
00129     enum ChannelStatus { SLEEP, IDLE, RECV, SEND }; 
00130     bool node_on_; // on-off status of this node
00131     Sleep_Timer sleep_timer_;
00132     int status_;
00133 
00134 private:
00135     inline int initialized() {
00136         return (node_ && uptarget_ && downtarget_ && propagation_);
00137     }
00138     void UpdateIdleEnergy();
00139     void UpdateSleepEnergy();
00140 
00141     // Convenience method
00142     EnergyModel* em() { return node()->energy_model(); }
00143 
00144     friend class Sleep_Timer;
00145 
00146 };
00147 
00148 #endif /* !ns_WirelessPhy_h */

Generated on Tue Mar 6 16:47:53 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6