• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/mac/wireless-phy.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/mac/wireless-phy.h,v 1.15 2007/01/30 05:00:50 tom_henderson 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         double T_sleep_;        // 2.31 change: Time at which sleeping is to be enabled (sec)
00100 
00101 protected:
00102         double Pt_;             // transmitted signal power (W)
00103         double Pt_consume_;     // power consumption for transmission (W)
00104         double Pr_consume_;     // power consumption for reception (W)
00105         double P_idle_;         // idle power consumption (W)
00106         double P_sleep_;        // sleep power consumption (W)
00107         double P_transition_;   // power consumed when transiting from SLEEP mode to IDLE mode and vice versa.
00108         double T_transition_;   // time period to transit from SLEEP mode to IDLE mode and vice versa.
00109 //
00110 
00111         double last_send_time_; // the last time the node sends somthing.
00112         double channel_idle_time_;      // channel idle time.
00113         double update_energy_time_;     // the last time we update energy.
00114 
00115         double freq_;           // frequency
00116         double lambda_;         // wavelength (m)
00117         double L_;              // system loss factor
00118   
00119         double RXThresh_;       // receive power threshold (W)
00120         double CSThresh_;       // carrier sense threshold (W)
00121         double CPThresh_;       // capture threshold (db)
00122   
00123         Antenna *ant_;
00124         Propagation *propagation_;      // Propagation Model
00125         Modulation *modulation_;        // Modulation Schem
00126 
00127         // Why phy has a node_ and this guy has it all over again??
00128 //      MobileNode* node_;              // Mobile Node to which interface is attached .
00129 
00130         enum ChannelStatus { SLEEP, IDLE, RECV, SEND }; 
00131         bool node_on_; // on-off status of this node
00132         Sleep_Timer sleep_timer_;
00133         int status_;
00134 
00135 private:
00136         inline int initialized() {
00137                 return (node_ && uptarget_ && downtarget_ && propagation_);
00138         }
00139         void UpdateIdleEnergy();
00140         void UpdateSleepEnergy();
00141 
00142         // Convenience method
00143         EnergyModel* em() { return node()->energy_model(); }
00144 
00145         friend class Sleep_Timer;
00146 
00147 };
00148 
00149 #endif /* !ns_WirelessPhy_h */

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