mac-timers.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 /* 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);
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 
00096 
00097 class IFTimer : public MacTimer {
00098 public:
00099     IFTimer(Mac802_11 *m) : MacTimer(m) {}
00100 
00101     void    handle(Event *e);
00102 };
00103 
00104 class NavTimer : public MacTimer {
00105 public:
00106     NavTimer(Mac802_11 *m) : MacTimer(m) {}
00107 
00108     void    handle(Event *e);
00109 };
00110 
00111 class RxTimer : public MacTimer {
00112 public:
00113     RxTimer(Mac802_11 *m) : MacTimer(m) {}
00114 
00115     void    handle(Event *e);
00116 };
00117 
00118 class TxTimer : public MacTimer {
00119 public:
00120     TxTimer(Mac802_11 *m) : MacTimer(m) {}
00121 
00122     void    handle(Event *e);
00123 };
00124 
00125 #endif /* __mac_timers_h__ */
00126 

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