• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/mac/mac-timers.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 /* Ported from CMU/Monarch's code, nov'98 -Padma.*/
00035 
00036 #ifndef __mac_timers_h__
00037 #define __mac_timers_h__
00038 
00039 /* ======================================================================
00040    Timers
00041    ====================================================================== */
00042 class Mac802_11;
00043 
00044 class MacTimer : public Handler {
00045 public:
00046         MacTimer(Mac802_11* m) : mac(m) {
00047                 busy_ = paused_ = 0; stime = rtime = 0.0;
00048         }
00049 
00050         virtual void handle(Event *e) = 0;
00051 
00052         virtual void start(double time);
00053         virtual void stop(void);
00054         virtual void pause(void) { assert(0); }
00055         virtual void resume(void) { assert(0); }
00056 
00057         inline int busy(void) { return busy_; }
00058         inline int paused(void) { return paused_; }
00059         inline double expire(void) {
00060                 return ((stime + rtime) - Scheduler::instance().clock());
00061         }
00062 
00063 protected:
00064         Mac802_11       *mac;
00065         int             busy_;
00066         int             paused_;
00067         Event           intr;
00068         double          stime;  // start time
00069         double          rtime;  // remaining time
00070 };
00071 
00072 
00073 class BackoffTimer : public MacTimer {
00074 public:
00075         BackoffTimer(Mac802_11 *m) : MacTimer(m), difs_wait(0.0) {}
00076 
00077 
00078 
00079         void    start(int cw, int idle, double difs = 0.0);
00080         void    handle(Event *e);
00081         void    pause(void);
00082         void    resume(double difs);
00083 private:
00084         double  difs_wait;
00085 };
00086 
00087 class DeferTimer : public MacTimer {
00088 public:
00089         DeferTimer(Mac802_11 *m) : MacTimer(m) {}
00090 
00091         void    start(double);
00092         void    handle(Event *e);
00093 };
00094 
00095 class BeaconTimer : public MacTimer {
00096 public:
00097         BeaconTimer(Mac802_11 *m) : MacTimer(m) {}
00098 
00099         void    start(double);
00100         void    handle(Event *e);
00101 };
00102 
00103 class ProbeTimer : public MacTimer {
00104 public:
00105         ProbeTimer(Mac802_11 *m) : MacTimer(m) {}
00106 
00107         void    start(double);
00108         void    handle(Event *e);
00109 };
00110 
00111 
00112 class IFTimer : public MacTimer {
00113 public:
00114         IFTimer(Mac802_11 *m) : MacTimer(m) {}
00115 
00116         void    handle(Event *e);
00117 };
00118 
00119 class NavTimer : public MacTimer {
00120 public:
00121         NavTimer(Mac802_11 *m) : MacTimer(m) {}
00122 
00123         void    handle(Event *e);
00124 };
00125 
00126 class RxTimer : public MacTimer {
00127 public:
00128         RxTimer(Mac802_11 *m) : MacTimer(m) {}
00129 
00130         void    handle(Event *e);
00131 };
00132 
00133 class TxTimer : public MacTimer {
00134 public:
00135         TxTimer(Mac802_11 *m) : MacTimer(m) {}
00136 
00137         void    handle(Event *e);
00138 };
00139 
00140 #endif /* __mac_timers_h__ */
00141 

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