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, double s = 0) : mac(m), slottime(s) { 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 double slottime; 00071 }; 00072 00073 00074 class BackoffTimer : public MacTimer { 00075 public: 00076 BackoffTimer(Mac802_11 *m, double s) : MacTimer(m, s), difs_wait(0.0) {} 00077 00078 void start(int cw, int idle); 00079 void handle(Event *e); 00080 void pause(void); 00081 void resume(double difs); 00082 private: 00083 double difs_wait; 00084 }; 00085 00086 class DeferTimer : public MacTimer { 00087 public: 00088 DeferTimer(Mac802_11 *m, double s) : MacTimer(m,s) {} 00089 00090 void start(double); 00091 void handle(Event *e); 00092 }; 00093 00094 class IFTimer : public MacTimer { 00095 public: 00096 IFTimer(Mac802_11 *m) : MacTimer(m) {} 00097 00098 void handle(Event *e); 00099 }; 00100 00101 class NavTimer : public MacTimer { 00102 public: 00103 NavTimer(Mac802_11 *m) : MacTimer(m) {} 00104 00105 void handle(Event *e); 00106 }; 00107 00108 class RxTimer : public MacTimer { 00109 public: 00110 RxTimer(Mac802_11 *m) : MacTimer(m) {} 00111 00112 void handle(Event *e); 00113 }; 00114 00115 class TxTimer : public MacTimer { 00116 public: 00117 TxTimer(Mac802_11 *m) : MacTimer(m) {} 00118 00119 void handle(Event *e); 00120 }; 00121 00122 #endif /* __mac_timers_h__ */ 00123
1.3.3