• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/wpan/p802_15_4timer.h

00001 /********************************************/
00002 /*     NS2 Simulator for IEEE 802.15.4      */
00003 /*           (per P802.15.4/D18)            */
00004 /*------------------------------------------*/
00005 /* by:        Jianliang Zheng               */
00006 /*        (zheng@ee.ccny.cuny.edu)          */
00007 /*              Myung J. Lee                */
00008 /*          (lee@ccny.cuny.edu)             */
00009 /*        ~~~~~~~~~~~~~~~~~~~~~~~~~         */
00010 /*           SAIT-CUNY Joint Lab            */
00011 /********************************************/
00012 
00013 // File:  p802_15_4timer.h
00014 // Mode:  C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t
00015 
00016 // $Header: /cvsroot/nsnam/ns-2/wpan/p802_15_4timer.h,v 1.2 2007/01/30 05:00:52 tom_henderson Exp $
00017 
00018 /*
00019  * Copyright (c) 2003-2004 Samsung Advanced Institute of Technology and
00020  * The City University of New York. All rights reserved.
00021  *
00022  * Redistribution and use in source and binary forms, with or without
00023  * modification, are permitted provided that the following conditions
00024  * are met:
00025  * 1. Redistributions of source code must retain the above copyright
00026  *    notice, this list of conditions and the following disclaimer.
00027  * 2. Redistributions in binary form must reproduce the above copyright
00028  *    notice, this list of conditions and the following disclaimer in the
00029  *    documentation and/or other materials provided with the distribution.
00030  * 3. All advertising materials mentioning features or use of this software
00031  *    must display the following acknowledgement:
00032  *      This product includes software developed by the Joint Lab of Samsung 
00033  *      Advanced Institute of Technology and The City University of New York.
00034  * 4. Neither the name of Samsung Advanced Institute of Technology nor of 
00035  *    The City University of New York may be used to endorse or promote 
00036  *    products derived from this software without specific prior written 
00037  *    permission.
00038  *
00039  * THIS SOFTWARE IS PROVIDED BY THE JOINT LAB OF SAMSUNG ADVANCED INSTITUTE
00040  * OF TECHNOLOGY AND THE CITY UNIVERSITY OF NEW YORK ``AS IS'' AND ANY EXPRESS 
00041  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00042  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 
00043  * NO EVENT SHALL SAMSUNG ADVANCED INSTITUTE OR THE CITY UNIVERSITY OF NEW YORK 
00044  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00045  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
00046  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
00047  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00048  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
00049  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00050  */
00051 
00052 
00053 #ifndef p802_15_4timer_h
00054 #define p802_15_4timer_h
00055 
00056 #include <scheduler.h>
00057 #include <assert.h>
00058 #include <math.h>
00059 
00060 class Mac802_15_4;
00061 
00062 //--base timer class for MAC sublayer---
00063 
00064 class Mac802_15_4Timer : public Handler
00065 {
00066 public:
00067         Mac802_15_4Timer();
00068         void            reset(void);
00069         virtual void    handle(Event *e) = 0;           
00070         virtual void    start(double time);
00071         virtual void    stop(void);
00072         virtual void    pause(void) {assert(0);}        //to be overloaded in subclass
00073         virtual void    resume(void) {assert(0);}       //to be overloaded in subclass
00074         inline int      busy(void) {return busy_;}
00075         inline int      paused(void) {return paused_;}
00076         inline double   expire(void)                    //remaining time
00077         {
00078                 return ((stime + wtime) - Scheduler::instance().clock());
00079         }
00080 
00081 protected:
00082         int             busy_;
00083         int             paused_;
00084         Event           event;
00085         double          stime;          //start time
00086         double          wtime;          //waiting time
00087 };
00088 
00089 //---timers for MAC sublayer---
00090 
00091 class CsmaCA802_15_4;
00092 class macBackoffTimer : public Mac802_15_4Timer
00093 {
00094 public:
00095         macBackoffTimer(CsmaCA802_15_4 *csma);
00096         //void  start(double time, double st, bool idle);
00097         void    handle(Event *e);
00098         //void  pause(void);
00099         //void  resume(double beacontime);
00100         /*
00101         inline void slot_wtime(double beacontime)       //calculate slot waiting time -- force timers to expire on slot boundries
00102         {
00103                 double rmd;
00104                 assert(slottime);
00105                 rmd = fmod(Scheduler::instance().clock() + wtime - beacontime, slottime);
00106                 if(rmd > 0.0)
00107                         wtime += (slottime - rmd);
00108                 else
00109                         wtime -= rmd;   //no effect
00110         }
00111         */
00112 private:
00113         CsmaCA802_15_4  *csmaca;
00114 };
00115 
00116 class macBeaconOtherTimer : public Mac802_15_4Timer
00117 {
00118 public:
00119         macBeaconOtherTimer(CsmaCA802_15_4 *csma);
00120         void    handle(Event *e);
00121 private:
00122         CsmaCA802_15_4  *csmaca;
00123 };
00124 
00125 class macDeferCCATimer : public Mac802_15_4Timer
00126 {
00127 public:
00128         macDeferCCATimer(CsmaCA802_15_4 *csma);
00129         void    handle(Event *e);
00130 private:
00131         CsmaCA802_15_4  *csmaca;
00132 };
00133 
00134 class macTxOverTimer : public Mac802_15_4Timer
00135 {
00136 public:
00137         macTxOverTimer(Mac802_15_4 *m) : Mac802_15_4Timer() {mac = m;}
00138         void    handle(Event *e);
00139 private:
00140         Mac802_15_4     *mac;
00141 };
00142 
00143 class macTxTimer : public Mac802_15_4Timer
00144 {
00145 public:
00146         macTxTimer(Mac802_15_4 *m) : Mac802_15_4Timer() {mac = m;}
00147         void    handle(Event *e);
00148 private:
00149         Mac802_15_4     *mac;
00150 };
00151 
00152 class macExtractTimer : public Mac802_15_4Timer
00153 {
00154 public:
00155         macExtractTimer(Mac802_15_4 *m) : Mac802_15_4Timer() {mac = m;onlyCAP = false;}
00156         void    backoffCAP(double time);
00157         void    start(double time,bool onlycap);
00158         void    stop(void);
00159         void    handle(Event *e);
00160         void    resume(void);
00161 private:
00162         Mac802_15_4     *mac;
00163         double          leftTime;
00164         bool            onlyCAP;
00165 };
00166 
00167 class macAssoRspWaitTimer : public Mac802_15_4Timer
00168 {
00169 public:
00170         macAssoRspWaitTimer(Mac802_15_4 *m) : Mac802_15_4Timer() {mac = m;}
00171         void    handle(Event *e);
00172 private:
00173         Mac802_15_4     *mac;
00174 };
00175 
00176 class macDataWaitTimer : public Mac802_15_4Timer
00177 {
00178 public:
00179         macDataWaitTimer(Mac802_15_4 *m) : Mac802_15_4Timer() {mac = m;}
00180         void    handle(Event *e);
00181 private:
00182         Mac802_15_4     *mac;
00183 };
00184 
00185 class macRxEnableTimer : public Mac802_15_4Timer
00186 {
00187 public:
00188         macRxEnableTimer(Mac802_15_4 *m) : Mac802_15_4Timer() {mac = m;}
00189         void    handle(Event *e);
00190 private:
00191         Mac802_15_4     *mac;
00192 };
00193 
00194 class macScanTimer : public Mac802_15_4Timer
00195 {
00196 public:
00197         macScanTimer(Mac802_15_4 *m) : Mac802_15_4Timer() {mac = m;}
00198         void    handle(Event *e);
00199 private:
00200         Mac802_15_4     *mac;
00201 };
00202 
00203 class macBeaconTxTimer : public Mac802_15_4Timer
00204 {
00205 public:
00206         macBeaconTxTimer(Mac802_15_4 *m) : Mac802_15_4Timer() {macBeaconOrder_last = 15; mac = m;}
00207         void    start(bool reset = false, bool fortx = false, double wt = 0.0);
00208         void    handle(Event *e);
00209 private:
00210         bool            forTX;
00211         unsigned char   macBeaconOrder_last;
00212         Mac802_15_4     *mac;
00213 };
00214 
00215 class macBeaconRxTimer : public Mac802_15_4Timer
00216 {
00217 public:
00218         macBeaconRxTimer(Mac802_15_4 *m) : Mac802_15_4Timer() {mac = m;lastTime = 0.0;}
00219         void    start(void);
00220         void    handle(Event *e);
00221 private:
00222         Mac802_15_4     *mac;
00223         double          lastTime;
00224 };
00225 
00226 class macBeaconSearchTimer : public Mac802_15_4Timer
00227 {
00228 public:
00229         macBeaconSearchTimer(Mac802_15_4 *m) : Mac802_15_4Timer() {mac = m;}
00230         void    handle(Event *e);
00231 private:
00232         Mac802_15_4     *mac;
00233 };
00234 
00235 //2.31 change: Timer to control node shutdown and wakeup
00236 class macWakeupTimer : public Mac802_15_4Timer
00237 {
00238 public:
00239         macWakeupTimer(Mac802_15_4 *m) : Mac802_15_4Timer() {mac = m;lastTime = 0.0;}
00240         void    start(void);
00241         void    handle(Event *e);
00242 private:
00243         Mac802_15_4     *mac;
00244         double          lastTime;
00245 };
00246 
00247 #endif
00248 
00249 // End of file: p802_15_4timer.h

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