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 Daedalus Research 00017 * Group at the University of California Berkeley. 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: /nfs/jade/vint/CVSROOT/ns-2/mac/mac-multihop.h,v 1.7 1998/06/27 01:24:07 gnguyen Exp $ (UCB) 00035 */ 00036 00037 #ifndef ns_mac_multihop_h 00038 #define ns_mac_multihop_h 00039 00040 #include "packet.h" 00041 #include "mac.h" 00042 #include "random.h" 00043 #include "ip.h" 00044 00045 #define MAC_POLLSIZE 40 /* completely arbitrary */ 00046 #define MAC_POLLACKSIZE 40 /* completely arbitrary */ 00047 00048 /* States of MultihopMac protocol */ 00049 #define MAC_IDLE 0x01 00050 #define MAC_POLLING 0x02 00051 #define MAC_RCV 0x04 00052 #define MAC_SND 0x08 00053 00054 #define MAC_TICK 16000 /* 1 tick = 1ms; 16 sub-ticks in a tick */ 00055 00056 00057 class MultihopMac; 00058 00059 /* 00060 * PollEvent class to generate poll events in the multihop 00061 * network prior to sending and receiving packets. 00062 */ 00063 00064 class PollEvent : public Event { 00065 public: 00066 PollEvent(MultihopMac* m, MultihopMac* pm) : 00067 backoffTime_(0), mac_(m), peerMac_(pm) { } 00068 int backoffTime_; /* valid only for NackPoll */ 00069 inline MultihopMac *peerMac() { return peerMac_; } 00070 protected: 00071 MultihopMac *mac_; /* pointer to my mac */ 00072 MultihopMac *peerMac_; /* pointer to my peer's mac */ 00073 }; 00074 00075 /* 00076 * Handle poll events. 00077 */ 00078 class PollHandler : public Handler { 00079 public: 00080 PollHandler(MultihopMac* m) { mac_ = m; } 00081 void handle(Event *); 00082 protected: 00083 MultihopMac* mac_; 00084 }; 00085 00086 /* 00087 * Handle pollack events. 00088 */ 00089 class PollAckHandler : public Handler { 00090 public: 00091 PollAckHandler(MultihopMac* m) { mac_ = m; } 00092 void handle(Event *); 00093 protected: 00094 MultihopMac* mac_; 00095 }; 00096 00097 /* 00098 * Handle pollnack events. 00099 */ 00100 class PollNackHandler : public Handler { 00101 public: 00102 PollNackHandler(MultihopMac* m) { mac_ = m; } 00103 void handle(Event *); 00104 protected: 00105 MultihopMac* mac_; 00106 }; 00107 00108 /* 00109 * Handle poll timeout events. 00110 */ 00111 class PollTimeoutHandler : public Handler { 00112 public: 00113 PollTimeoutHandler(MultihopMac* m) { mac_ = m; } 00114 void handle(Event *); 00115 protected: 00116 MultihopMac* mac_; 00117 }; 00118 00119 class BackoffHandler : public Handler { 00120 public: 00121 BackoffHandler(MultihopMac *m) { mac_ = m; } 00122 void handle(Event *); 00123 protected: 00124 MultihopMac* mac_; 00125 }; 00126 00127 /* 00128 class MultihopMacHandler : public Handler { 00129 public: 00130 MultihopMacHandler(MultihopMac* m) { mac_ = m; } 00131 void handle(Event *e); 00132 protected: 00133 MultihopMac* mac_; 00134 }; 00135 */ 00136 00137 class MultihopMac : public Mac { 00138 public: 00139 MultihopMac(); 00140 void send(Packet*); /* send data packet (assume POLLed) link */ 00141 void recv(Packet *, Handler *); /* call from higher layer (LL) */ 00142 void poll(Packet *); /* poll peer mac */ 00143 int checkInterfaces(int); /* probe state of this and other MACs */ 00144 void schedulePoll(MultihopMac *); /* schedule poll for later */ 00145 inline int mode() { return mode_; } 00146 inline int mode(int m) { return mode_ = m; } 00147 inline MultihopMac *peer() { return peer_; } 00148 inline MultihopMac *peer(MultihopMac *p) { return peer_ = p; } 00149 inline double tx_rx() { return tx_rx_; } /* access tx_rx time */ 00150 inline double rx_tx() { return rx_tx_; } /* access rx_tx time */ 00151 inline double rx_rx() { return rx_rx_; } /* access rx_rx time */ 00152 inline double backoffBase() { return backoffBase_; } 00153 inline double backoffTime() { return backoffTime_; } 00154 inline double backoffTime(double bt) { return backoffTime_ = bt; } 00155 inline PollEvent *pendingPE() { return pendingPollEvent_; } 00156 inline PollEvent *pendingPE(PollEvent *pe) { return pendingPollEvent_ = pe; } 00157 inline Packet *pkt() { return pkt_; } 00158 inline PollHandler* ph() { return &ph_; } /* access poll handler */ 00159 inline PollAckHandler* pah() { return &pah_; } 00160 inline PollNackHandler* pnh() { return &pnh_; } 00161 inline PollTimeoutHandler* pth() { return &pth_; } 00162 inline BackoffHandler* bh() { return &bh_; } 00163 // inline MultihopMacHandler* mh() { return &mh_; } 00164 inline double pollTxtime(int s) { return (double) s*8.0/bandwidth(); } 00165 protected: 00166 int mode_; /* IDLE/SND/RCV */ 00167 MultihopMac *peer_; /* peer mac */ 00168 double tx_rx_; /* Turnaround times: transmit-->recv */ 00169 double rx_tx_; /* recv-->transmit */ 00170 double rx_rx_; /* recv-->recv */ 00171 double backoffTime_; 00172 double backoffBase_; 00173 PollEvent *pendingPollEvent_; /* pending in scheduler */ 00174 Packet *pkt_; /* packet stored for poll retries */ 00175 PollHandler ph_; /* handler for POLL events */ 00176 PollAckHandler pah_; /* handler for POLL_ACK events */ 00177 PollNackHandler pnh_; /* handler for POLL_NACK events */ 00178 PollTimeoutHandler pth_;/* handler for POLL_TIMEOUT events */ 00179 BackoffHandler bh_; /* handler for exponential backoffs */ 00180 // MultihopMacHandler mh_; /* handle receives of data */ 00181 }; 00182 00183 00184 #endif
1.4.6